forked from pool/python-Dumper
osc copypac from project:devel:languages:python package:python-dumper revision:2
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-Dumper?expand=0&rev=1
This commit is contained in:
23
.gitattributes
vendored
Normal file
23
.gitattributes
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
## Default LFS
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.bsp filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.gem filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.jar filter=lfs diff=lfs merge=lfs -text
|
||||
*.lz filter=lfs diff=lfs merge=lfs -text
|
||||
*.lzma filter=lfs diff=lfs merge=lfs -text
|
||||
*.obscpio filter=lfs diff=lfs merge=lfs -text
|
||||
*.oxt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.rpm filter=lfs diff=lfs merge=lfs -text
|
||||
*.tbz filter=lfs diff=lfs merge=lfs -text
|
||||
*.tbz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||
*.txz filter=lfs diff=lfs merge=lfs -text
|
||||
*.whl filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.osc
|
||||
3
Dumper-1.2.0.tar.gz
Normal file
3
Dumper-1.2.0.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:36a0e517138626691b3c9c3baa0577b49c3eba07620bf6ee0437def9715b5c89
|
||||
size 11915
|
||||
9
python-Dumper.changes
Normal file
9
python-Dumper.changes
Normal file
@@ -0,0 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Sat Jan 8 08:03:17 UTC 2022 - Matej Cepl <mcepl@suse.com>
|
||||
|
||||
- Add test.py and run tests.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Sep 15 09:57:07 UTC 2021 - Jens K. <karatekhd@opensuse.org>
|
||||
|
||||
-
|
||||
58
python-Dumper.spec
Normal file
58
python-Dumper.spec
Normal file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# spec file for package python-Dumper
|
||||
#
|
||||
# Copyright (c) 2022 SUSE LLC
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
# upon. The license for this file, and modifications and additions to the
|
||||
# file, is the same license as for the pristine package itself (unless the
|
||||
# license for the pristine package is not an Open Source License, in which
|
||||
# case the license is the MIT License). An "Open Source License" is a
|
||||
# license that conforms to the Open Source Definition (Version 1.9)
|
||||
# published by the Open Source Initiative.
|
||||
|
||||
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
||||
#
|
||||
|
||||
|
||||
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
|
||||
Name: python-Dumper
|
||||
Version: 1.2.0
|
||||
Release: 0
|
||||
Summary: Tool to conveniently describe any Python datastructure
|
||||
License: MIT
|
||||
URL: https://github.com/jric/Dumper.py
|
||||
Source0: https://files.pythonhosted.org/packages/source/D/Dumper/Dumper-%{version}.tar.gz
|
||||
Source1: https://raw.githubusercontent.com/jric/Dumper.py/master/test.py
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: fdupes
|
||||
BuildRequires: python-rpm-macros
|
||||
BuildArch: noarch
|
||||
%python_subpackages
|
||||
|
||||
%description
|
||||
Tool to conveniently describe any Python datastructure
|
||||
|
||||
%prep
|
||||
%setup -q -n Dumper-%{version}
|
||||
cp %{SOURCE1} .
|
||||
|
||||
%build
|
||||
%python_build
|
||||
|
||||
%install
|
||||
%python_install
|
||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||
|
||||
%check
|
||||
%{python_expand export PYTHONPATH=%{buildroot}%{$python_sitelib}
|
||||
$python test.py
|
||||
}
|
||||
|
||||
%files %{python_files}
|
||||
%doc README.md
|
||||
%{python_sitelib}/dumper/
|
||||
%{python_sitelib}/Dumper-%{version}-py*.egg-info
|
||||
|
||||
%changelog
|
||||
118
test.py
Normal file
118
test.py
Normal file
@@ -0,0 +1,118 @@
|
||||
from __future__ import print_function
|
||||
from dumper import dump, dumps, Dumper
|
||||
import dumper
|
||||
import io
|
||||
import sys
|
||||
|
||||
buff = io.StringIO()
|
||||
dumper.default_dumper = Dumper(output=buff)
|
||||
|
||||
# BEGIN TEST CASES
|
||||
|
||||
def do_dump_scalars():
|
||||
dump(1)
|
||||
dump('a')
|
||||
dump("foo")
|
||||
dump('''string
|
||||
with a newline''')
|
||||
return "1'a''foo''string\\nwith a newline'"
|
||||
|
||||
def test_do_dump_scalars():
|
||||
assert_output_as_expected(do_dump_scalars)
|
||||
|
||||
def do_dumps_multi_values():
|
||||
s = dumps(1, " is less than ", 10) # returns unicode string in py2
|
||||
if sys.version < (3, 0):
|
||||
s = s.encode('ascii', 'replace') # convert back to regular string
|
||||
dump(s)
|
||||
return "\"1' is less than '10\""
|
||||
|
||||
def test_dumps_multi_values():
|
||||
assert_output_as_expected(do_dumps_multi_values)
|
||||
|
||||
def do_dump_json():
|
||||
obj = {
|
||||
"httpCode": 200,
|
||||
"extensionData": [
|
||||
{
|
||||
"extensionValue": "egg"
|
||||
}
|
||||
]
|
||||
}
|
||||
dump(obj)
|
||||
return '''
|
||||
<dict at {WORD}>:
|
||||
httpCode: 200
|
||||
extensionData: <list at {WORD}>
|
||||
0: <dict at {WORD}>:
|
||||
extensionValue: 'egg'
|
||||
'''
|
||||
|
||||
def test_do_dump_json():
|
||||
assert_output_matches_template(do_dump_json)
|
||||
|
||||
# END TEST CASES
|
||||
|
||||
def text_type(val):
|
||||
if sys.version < '3':
|
||||
return unicode(val)
|
||||
else:
|
||||
return str(val)
|
||||
|
||||
def assertMatching(a, b):
|
||||
''' Asserts that the lines from string, a, match the lines in the string, b.
|
||||
a is the expected string / pattern
|
||||
b is the actual string
|
||||
We ignore leading/trailing whitespace
|
||||
'''
|
||||
a_lines = a.strip().split("\n")
|
||||
b_lines = b.strip().split("\n")
|
||||
if len(a_lines) != len(b_lines):
|
||||
raise AssertionError("a has " + text_type(len(a_lines)) + ", but b has " + text_type(len(b_lines)) + " lines: a={" + a + "}, b={" + b + "}")
|
||||
for i in range(0, len(a_lines)):
|
||||
assert a_lines[i] == b_lines[i]
|
||||
|
||||
def assert_output_matches_template(func):
|
||||
# TODO: implement this
|
||||
pass
|
||||
|
||||
def assert_output_as_expected(func):
|
||||
# buffer stdout
|
||||
try:
|
||||
output = func()
|
||||
assertMatching(output, buff.getvalue())
|
||||
finally:
|
||||
# reset the buffer for the next test
|
||||
buff.truncate(0)
|
||||
buff.seek(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
l1 = [3, 5, 'hello']
|
||||
t1 = ('uh', 'oh')
|
||||
l2 = ['foo', t1]
|
||||
d1 = {'k1': 'val1',
|
||||
'k2': l1,
|
||||
'k2': l2}
|
||||
|
||||
print("a list: ", dumps (l1), "; a tuple: ", dumps (t1))
|
||||
print("a complex list: ")
|
||||
dump (l2)
|
||||
dump (d1)
|
||||
print("same dict, printed from dumps(): ")
|
||||
print(dumps(d1))
|
||||
dump (19)
|
||||
dump ("\nMy birth year!\n")
|
||||
|
||||
dumper = Dumper (max_depth=1)
|
||||
l = ['foo', ['bar', 'baz', (1, 2, 3)]]
|
||||
dumper.dump (l)
|
||||
dumper.max_depth = 2
|
||||
dumper.dump (l)
|
||||
l[1][2] = tuple (range (11))
|
||||
dumper.dump (l)
|
||||
dumper.max_depth = None
|
||||
print(dumper.max_depth)
|
||||
|
||||
class Foo: pass
|
||||
class Bar: pass
|
||||
Reference in New Issue
Block a user