aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2012-02-27 18:54:37 +0100
committerMatěj Cepl <mcepl@redhat.com>2012-02-27 18:54:37 +0100
commitd9f2aa1f9d1066a168700c4e356db4f26772468a (patch)
treeafe42448063640b6b822e95c032fd649a6be353d
parenta9adb2cae3d62d95a1fdc57d7137dca5e5b9ada9 (diff)
downloadyamlish-d9f2aa1f9d1066a168700c4e356db4f26772468a.tar.gz
Temporary commit to make files available
-rw-r--r--failing_test.py57
-rw-r--r--test/__init__.py13
-rw-r--r--test/all_tests.py23
-rw-r--r--test/test_input.py11
-rw-r--r--test/test_output.py32
-rw-r--r--test/test_reader.py12
-rw-r--r--yamlish.py21
7 files changed, 62 insertions, 107 deletions
diff --git a/failing_test.py b/failing_test.py
index a188f33..7a2f655 100644
--- a/failing_test.py
+++ b/failing_test.py
@@ -1,50 +1,15 @@
#!/usr/bin/python
+from __future__ import absolute_import, print_function, unicode_literals
import yaml
-IN = {
- "name": 'Hello World 6',
- "in": [
- "---",
- "- \"\\z\\x01\\x02\\x03\\x04\\x05\\x06\\a\\x08\\t\\n\\v\\f\\r\\x0e\\x0f\"",
- "- \"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\e\\x1c\\x1d\\x1e\\x1f\"",
- "- \" !\\\"#\$%&'()*+,-./\"",
- "- 0123456789:;<=>?",
- "- '\@ABCDEFGHIJKLMNO'",
- "- 'PQRSTUVWXYZ[\\]^_'",
- "- '`abcdefghijklmno'",
- "- 'pqrstuvwxyz{|}~\177'",
- "- \200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
- "- \220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
- "- \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
- "- \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
- "- \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
- "- \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
- "- \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
- "- \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377",
- "..."
- ],
- "out": [
- "\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17",
- "\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37",
- " !\"#\$%&'()*+,-./",
- "0123456789:;<=>?",
- "\@ABCDEFGHIJKLMNO",
- "PQRSTUVWXYZ[\\]^_",
- "`abcdefghijklmno",
- "pqrstuvwxyz{|}~\177",
- "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
- "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
- "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
- "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
- "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
- "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
- "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
- "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
- ]
- }
+inobj = {
+ "date": "2001-01-23",
+ "state": "MI",
+ "quantity": 4
+ }
-instr = "\n".join(IN['in'])
-print "type instr = %s" % type(instr)
-print instr
-res = yaml.load(instr, Loader=yaml.SafeLoader)
-print "'%s'" % (res == IN['out'])
+print("type inobj = %s" % type(inobj))
+print(inobj)
+res = yaml.dump(inobj, encoding="utf-8", default_flow_style=False,
+ default_style=False, canonical=False, Dumper=yaml.SafeDumper)
+print("'%s'" % res)
diff --git a/test/__init__.py b/test/__init__.py
index cb37281..b66ce57 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -5,7 +5,7 @@ from test import test_reader, test_input
import yamlish
import unittest
import yaml
-logging.basicConfig(level=logging.DEBUG)
+logging.basicConfig(level=logging.INFO)
def _generate_test_name(source):
"""
@@ -55,14 +55,3 @@ def generate_testsuite(test_data, test_case_shell, test_fce):
test_method = _create_test (in_test, test_fce)
test_method.__name__ = str('test_%s' % name) # IGNORE:W0622
setattr (test_case_shell, test_method.__name__, test_method)
-
-class TestInput(unittest.TestCase): # IGNORE:C0111
- pass
-
-class TestReader(unittest.TestCase): # IGNORE:C0111
- pass
-
-if __name__ == "__main__":
- generate_testsuite(test_reader.test_data_list, TestReader, yamlish.load)
- generate_testsuite(test_input.test_data_list, TestInput, yamlish.load)
- unittest.main()
diff --git a/test/all_tests.py b/test/all_tests.py
deleted file mode 100644
index 66e069b..0000000
--- a/test/all_tests.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import sys
-import os.path
-sys.path.insert(0, os.path.realpath(os.path.dirname(__file__) + "/.."))
-
-import logging
-logging.basicConfig(level=logging.INFO)
-import unittest
-import test_load
-import test_input
-import test_reader
-import test_output
-import test_writer
-
-if __name__ == "__main__":
- loader = unittest.TestLoader()
- suite = loader.loadTestsFromModule(test_load)
- #suite.addTests(loader.loadTestsFromModule(test_input))
- suite.addTests(loader.loadTestsFromModule(test_reader))
- #suite.addTests(loader.loadTestsFromModule(test_output))
- #suite.addTests(loader.loadTestsFromModule(test_writer))
-
- runner = unittest.TextTestRunner(verbosity=2)
- result = runner.run(suite)
diff --git a/test/test_input.py b/test/test_input.py
index d950f86..6ed6a6f 100644
--- a/test/test_input.py
+++ b/test/test_input.py
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
+import test
+import unittest
+import yamlish
+
test_data_list = [
{
"name": "Input test",
@@ -64,3 +68,10 @@ total: 4443.52
}
}
]
+
+class TestInput(unittest.TestCase): # IGNORE:C0111
+ pass
+
+if __name__ == "__main__":
+ test.generate_testsuite(test_data_list, TestInput, yamlish.load)
+ unittest.main()
diff --git a/test/test_output.py b/test/test_output.py
index cebd66d..4ed050f 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -44,31 +44,31 @@ IN = {
'given': 'Chris',
'address': {
'city': 'Royal Oak',
- 'postal': '48046',
- 'lines': "458 Walkman Dr.\nSuite #292\n",
+ 'postal': 48046,
+ 'lines': "458 Walkman Dr.\\nSuite #292\\n",
'state': 'MI'
},
'family': 'Dumars'
},
- 'invoice': '34843',
+ 'invoice': 34843,
'date': '2001-01-23',
- 'tax': '251.42',
+ 'tax': 251.42,
'product': [
{
'sku': 'BL394D',
- 'quantity': '4',
- 'price': '450.00',
+ 'quantity': 4,
+ 'price': 450.00,
'description': 'Basketball'
},
{
'sku': 'BL4438H',
- 'quantity': '1',
- 'price': '2392.00',
+ 'quantity': 1,
+ 'price': 2392.00,
'description': 'Super Hoop'
}
],
- 'comments': "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
- 'total': '4443.52'
+ 'comments': "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\\n",
+ 'total': 4443.52
}
buf1 = []
@@ -100,10 +100,10 @@ class TestOuptut(unittest.TestCase):
"""
self._expected = ""
for line in OUT:
- self._expected += "%s\n" % line
+ self._expected += line + "\n"
- def test_file_output(self):
+ def notest_file_output(self):
"""
Test output to a file.
"""
@@ -124,10 +124,10 @@ class TestOuptut(unittest.TestCase):
"""
got = yamlish.dumps(IN)
self.assertEqual(got, self._expected, """Result matches
- expected = %s
-
- observed = %s
- """ % (self._expected, got))
+ expected = %s
+
+ observed = %s
+ """ % (self._expected, got))
if __name__ == "__main__":
unittest.main()
diff --git a/test/test_reader.py b/test/test_reader.py
index 79756c9..8c681c8 100644
--- a/test/test_reader.py
+++ b/test/test_reader.py
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import yaml
+import yamlish
+import test
+import unittest
test_data_list = [
{
@@ -39,7 +42,7 @@ test_data_list = [
},
{
"name": 'Mixed array',
- "in": [ '---', '- 1', "- 'two'", r'- "three\n"', '...', ],
+ "in": [ '---', '- 1', "- 'two'", '- "three\n"', '...', ],
"out": [ 1, 'two', "three\n" ],
},
{
@@ -359,3 +362,10 @@ test_data_list = [
},
},
]
+
+class TestReader(unittest.TestCase): # IGNORE:C0111
+ pass
+
+if __name__ == "__main__":
+ test.generate_testsuite(test_data_list, TestReader, yamlish.load)
+ unittest.main()
diff --git a/yamlish.py b/yamlish.py
index d7be098..098e03d 100644
--- a/yamlish.py
+++ b/yamlish.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import, print_function, unicode_literals
"""
Easy YAML serialisation compatible with TAP (http://testanything.org/) format.
Copyright (C) 2012 Red Hat, Inc.
@@ -150,15 +151,15 @@ def load(source):
many others).
"""
out = None
- logging.debug("instr:\n%s", source)
+ logging.debug("inobj:\n%s", source)
if isinstance(source, (str, unicode)):
out = yaml.load(source, Loader=_YamlishLoader)
logging.debug("out (string) = %s", out)
elif hasattr(source, "__iter__"):
- instr = ""
+ inobj = ""
for line in source:
- instr += line + '\n'
- out = load(instr)
+ inobj += line + '\n'
+ out = load(inobj)
logging.debug("out (iter) = %s", out)
return out
@@ -172,13 +173,15 @@ def dump(source, destination):
with open(destination, "w") as outf:
dump(source, outf)
elif isinstance(destination, file):
- yaml.dump(source, destination, canonical=False,
- allow_unicode=False,
- default_flow_style=False, default_style=False)
+ yaml.dump(source, destination, encoding="utf-8",
+ default_flow_style=False, canonical=False,
+ Dumper=yaml.SafeDumper)
def dumps(source):
"""
Return YAMLish string from given source.
"""
- return yaml.dump(source, canonical=False, allow_unicode=False,
- default_flow_style=False, default_style=False)
+ return yaml.dump(source, encoding="utf-8",
+ explicit_start=True, explicit_end=True,
+ default_flow_style=False, default_style=False,
+ canonical=False, Dumper=yaml.SafeDumper)