diff --git a/tests/test_lib.py b/tests/test_jc_lib.py similarity index 100% rename from tests/test_lib.py rename to tests/test_jc_lib.py diff --git a/tests/test_jc_streaming.py b/tests/test_jc_streaming.py new file mode 100644 index 00000000..7f11778b --- /dev/null +++ b/tests/test_jc_streaming.py @@ -0,0 +1,61 @@ +import unittest +import jc.streaming + + +class MyTests(unittest.TestCase): + + def test_streaming_input_type_check_wrong(self): + self.assertRaises(TypeError, jc.streaming.streaming_input_type_check, 'abc') + + + def test_streaming_input_type_check_correct(self): + self.assertEqual(jc.streaming.streaming_input_type_check(['abc']), None) + + + def test_streaming_line_input_type_check_wrong(self): + self.assertRaises(TypeError, jc.streaming.streaming_line_input_type_check, ['abc']) + + + def test_streaming_line_input_type_check_correct(self): + self.assertEqual(jc.streaming.streaming_line_input_type_check('abc'), None) + + + def test_stream_success_ignore_exceptions_true(self): + self.assertEqual(jc.streaming.stream_success({}, True), {'_jc_meta': {'success': True}}) + + + def test_stream_success_ignore_exceptions_false(self): + self.assertEqual(jc.streaming.stream_success({}, False), {}) + + + def test_stream_error(self): + self.assertEqual(jc.streaming.stream_error( + TypeError, 'this is a test'), + { + '_jc_meta': + { + 'success': False, + 'error': 'type: ', + 'line': 'this is a test' + } + } + ) + + + def test_raise_or_yield_ignore_exceptions(self): + self.assertEqual(jc.streaming.raise_or_yield( + True, TypeError, 'this is a test'), + (TypeError, 'this is a test') + ) + + + def test_raise_or_yield_ignore_exceptions_false(self): + self.assertRaises( + TypeError, + jc.streaming.raise_or_yield, + False, TypeError, 'this is a test' + ) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_utils.py b/tests/test_jc_utils.py similarity index 81% rename from tests/test_utils.py rename to tests/test_jc_utils.py index 35334b02..1f8a14b1 100644 --- a/tests/test_utils.py +++ b/tests/test_jc_utils.py @@ -127,6 +127,7 @@ class MyTests(unittest.TestCase): '0.0': False, '0.1': True, '-0.1': True, + '*': True, 'true': True, 'True': True, 'false': False, @@ -147,3 +148,46 @@ class MyTests(unittest.TestCase): for input_string, expected_output in io_map.items(): self.assertEqual(jc.utils.convert_to_bool(input_string), expected_output) + + + def test_has_data_nodata(self): + self.assertFalse(jc.utils.has_data(' \n ')) + + + def test_has_data_withdata(self): + self.assertTrue(jc.utils.has_data(' \n abcd \n ')) + + + def test_input_type_check_wrong(self): + self.assertRaises(TypeError, jc.utils.input_type_check, ['abc']) + + + def test_input_type_check_correct(self): + self.assertEqual(jc.utils.input_type_check('abc'), None) + + + # need to mock shutil.get_terminal_size().columns or add a column parameter to test + # def test_warning_message(self): + # msg = [ + # 'this is a long first line that will be wrapped yada yada yada yada yada yada yada.', + # 'this is a second long line that will be wrapped yada yada yada yada yada yada yada yada yada.', + # 'this is a third long line that will be wrapped yada yada yada yada yada yada yada yada yada.' + # ] + + # expected = '''jc: Warning - this is a long first line that will be wrapped yada yada yada + # yada yada yada yada. + # this is a second long line that will be wrapped yada yada yada + # yada yada yada yada yada yada. + # this is a third long line that will be wrapped yada yada yada + # yada yada yada yada yada yada.''' + + # f = io.StringIO() + # with contextlib.redirect_stderr(f): + # jc.utils.warning_message(msg) + + # self.assertEqual(f.getvalue(), expected + '\n') + + + +if __name__ == '__main__': + unittest.main()