Commit d9f2aa1f authored by Matěj Cepl's avatar Matěj Cepl

Temporary commit to make files available

parent a9adb2ca
#!/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)
......@@ -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()
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)
# -*- 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()
......@@ -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()
# -*- 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()
# -*- 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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment