aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/__init__.py17
-rw-r--r--test/test_load.py9
-rw-r--r--test/test_output.py8
-rw-r--r--test/test_reader.py6
-rw-r--r--test/test_writer.py10
5 files changed, 19 insertions, 31 deletions
diff --git a/test/__init__.py b/test/__init__.py
index 1c5c139..8005917 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -2,18 +2,14 @@
from __future__ import absolute_import, print_function, unicode_literals
import logging
import yamlish
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
import yaml
import tempfile
import textwrap
-from textwrap import dedent
INPUT = 1
OUTPUT = 2
+
def _generate_test_name(source):
"""
Clean up human-friendly test name into a method name.
@@ -21,6 +17,7 @@ def _generate_test_name(source):
out = source.replace(' ', '_').replace(':', '').replace(',', '').lower()
return "test_%s" % out
+
def _create_input_test(test_src, tested_function):
"""
Decorate tested function to be used as a method for TestCase.
@@ -77,10 +74,10 @@ def _create_output_test(test_src, tested_function):
return do_test_expected
-
def generate_testsuite(test_data, test_case_shell, test_fce, direction=INPUT):
"""
- Generate tests from the test data, class to build upon and function to use for testing.
+ Generate tests from the test data, class to build upon and function
+ to use for testing.
"""
for in_test in test_data:
if ('skip' in in_test) and in_test['skip']:
@@ -88,8 +85,8 @@ 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)
+ test_method = _create_input_test(in_test, test_fce)
elif direction == OUTPUT:
test_method = _create_output_test(in_test, test_fce)
- test_method.__name__ = str('test_%s' % name) # IGNORE:W0622
- setattr (test_case_shell, test_method.__name__, test_method)
+ test_method.__name__ = str('test_%s' % name)
+ setattr(test_case_shell, test_method.__name__, test_method)
diff --git a/test/test_load.py b/test/test_load.py
index 7a76ae1..0b16044 100644
--- a/test/test_load.py
+++ b/test/test_load.py
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
+
class TestBasics(unittest.TestCase):
def test_import(self):
import yamlish
self.assertTrue(yamlish.__version__,
- "Testing import of yamlish, version %s." % yamlish.__version__)
+ "Testing import of yamlish, version %s."
+ % yamlish.__version__)
if __name__ == "__main__":
unittest.main()
diff --git a/test/test_output.py b/test/test_output.py
index 1105b84..3762408 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -5,14 +5,11 @@ Test general output functionality.
Without much stress on the format itself.
"""
from __future__ import absolute_import, print_function, unicode_literals
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
import yamlish
import yaml
import logging
import tempfile
+import unittest
OUT = """---
bill-to:
@@ -74,6 +71,7 @@ IN = {
'total': 4443.52
}
+
class TestOuptut(unittest.TestCase):
def setUp(self):
"""
@@ -81,7 +79,6 @@ class TestOuptut(unittest.TestCase):
"""
self._expected = yaml.safe_load(OUT)
-
def test_file_output(self):
"""
Test output to a file.
@@ -95,7 +92,6 @@ class TestOuptut(unittest.TestCase):
got = yaml.safe_load(got_str)
self.assertEqual(got, self._expected, "Result matches")
-
def test_string_output(self):
"""
Test output to a string.
diff --git a/test/test_reader.py b/test/test_reader.py
index a34104c..166fc8f 100644
--- a/test/test_reader.py
+++ b/test/test_reader.py
@@ -3,10 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import yaml
import yamlish
import test
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
test_data_list = [
{
@@ -365,6 +362,7 @@ test_data_list = [
},
]
+
class TestReader(unittest.TestCase): # IGNORE:C0111
pass
diff --git a/test/test_writer.py b/test/test_writer.py
index a3f3893..f8186d1 100644
--- a/test/test_writer.py
+++ b/test/test_writer.py
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
import test
import yamlish
@@ -191,10 +187,12 @@ test_data_list = [
},
]
+
class TestWriter(unittest.TestCase): # IGNORE:C0111
pass
-test.generate_testsuite(test_data_list, TestWriter, yamlish.dump, direction=test.OUTPUT)
+test.generate_testsuite(test_data_list, TestWriter, yamlish.dump,
+ direction=test.OUTPUT)
if __name__ == "__main__":
unittest.main()