aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-01-13 11:33:23 +0100
committerMatěj Cepl <mcepl@cepl.eu>2015-01-13 11:37:47 +0100
commit4917a0dd34d7d53dae73a24808e0ff95bfd32ab2 (patch)
treee3fc350032cbf54cbb48d6e467347cc6c8a98566 /test
parentdeba136e5016e45310ba2a0331a15c3ed47db5d1 (diff)
downloadyamlish-4917a0dd34d7d53dae73a24808e0ff95bfd32ab2.tar.gz
Fix testsuite under py3k
We don't support python 3.1, and 3.2 ... if anybody provides patches, I will accept them, but otherwise I cannot make myself to care.
Diffstat (limited to 'test')
-rw-r--r--test/__init__.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/__init__.py b/test/__init__.py
index 1cb1ad0..85cadbd 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -9,8 +9,12 @@ import textwrap
INPUT = 1
OUTPUT = 2
+if yamlish.py3k:
+ unicode = str
+
#logging.basicConfig(level=logging.DEBUG)
+
def _generate_test_name(source):
"""
Clean up human-friendly test name into a method name.
@@ -37,7 +41,8 @@ def _create_input_test(test_src, tested_function, options=None):
want = test_src['out']
got = tested_function(test_src['in'], options)
logging.debug('got = type %s', type(got))
- logging.debug("test_src['out'] = %s", unicode(test_src['out']))
+ logging.debug("test_src['out'] = %s",
+ unicode(test_src['out']))
self.assertEqual(got, want, """Result matches
expected = %s
@@ -60,7 +65,8 @@ def _create_output_test(test_src, tested_function, options=None):
# We currently don't throw any exceptions in Writer, so this
# this is always false
if 'error' in test_src:
- self.assertRaises(test_src['error'], yamlish.dumps, test_src['in'], options)
+ self.assertRaises(test_src['error'], yamlish.dumps,
+ test_src['in'], options)
else:
logging.debug("out:\n%s", textwrap.dedent(test_src['out']))
want = yaml.load(textwrap.dedent(test_src['out']))
@@ -77,7 +83,7 @@ def _create_output_test(test_src, tested_function, options=None):
def generate_testsuite(test_data, test_case_shell, test_fce, direction=INPUT,
- options=None):
+ options=None):
"""
Generate tests from the test data, class to build upon and function
to use for testing.
@@ -88,8 +94,10 @@ def generate_testsuite(test_data, test_case_shell, test_fce, direction=INPUT,
continue
name = _generate_test_name(in_test['name'])
if direction == INPUT:
- test_method = _create_input_test(in_test, test_fce, options=options)
+ test_method = _create_input_test(in_test, test_fce,
+ options=options)
elif direction == OUTPUT:
- test_method = _create_output_test(in_test, test_fce, options=options)
+ test_method = _create_output_test(in_test, test_fce,
+ options=options)
test_method.__name__ = str('test_%s' % name)
setattr(test_case_shell, test_method.__name__, test_method)