From 23ff19fdb503f9c890f79263d8f866367e294c45 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 31 Jan 2023 06:48:37 -0800 Subject: [PATCH] add slicer tests --- tests/test_jc_cli.py | 124 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/tests/test_jc_cli.py b/tests/test_jc_cli.py index 6981ebc6..5bfc13d2 100644 --- a/tests/test_jc_cli.py +++ b/tests/test_jc_cli.py @@ -329,5 +329,129 @@ class MyTests(unittest.TestCase): cli.add_metadata_to_output() self.assertEqual(cli.data_out, expected) + def test_slice_none_str(self): + cli = JcCli() + cli.slice_start = None + cli.slice_end = None + cli.data_in = '''\ + row0 + row1 + row2 + row3 + row4 + row5''' + expected = '''\ + row0 + row1 + row2 + row3 + row4 + row5''' + cli.slicer() + self.assertEqual(cli.data_in, expected) + + def test_slice_positive_str(self): + cli = JcCli() + cli.slice_start = 1 + cli.slice_end = 5 + cli.data_in = '''\ + row0 + row1 + row2 + row3 + row4 + row5''' + expected = '''\ + row1 + row2 + row3 + row4''' + cli.slicer() + self.assertEqual(cli.data_in, expected) + + def test_slice_negative_str(self): + cli = JcCli() + cli.slice_start = 1 + cli.slice_end = -1 + cli.data_in = '''\ + row0 + row1 + row2 + row3 + row4 + row5''' + expected = '''\ + row1 + row2 + row3 + row4''' + cli.slicer() + self.assertEqual(cli.data_in, expected) + + def test_slice_none_iter(self): + cli = JcCli() + cli.slice_start = None + cli.slice_end = None + cli.data_in = [ + 'row0', + 'row1', + 'row2', + 'row3', + 'row4', + 'row5' + ] + expected = [ + 'row0', + 'row1', + 'row2', + 'row3', + 'row4', + 'row5' + ] + cli.slicer() + self.assertEqual(cli.data_in, expected) + + def test_slice_positive_iter(self): + cli = JcCli() + cli.slice_start = 1 + cli.slice_end = 5 + cli.data_in = [ + 'row0', + 'row1', + 'row2', + 'row3', + 'row4', + 'row5' + ] + expected = [ + 'row1', + 'row2', + 'row3', + 'row4' + ] + cli.slicer() + self.assertEqual(list(cli.data_in), expected) + + def test_slice_negative_iter(self): + cli = JcCli() + cli.slice_start = 1 + cli.slice_end = -1 + cli.data_in = [ + 'row0', + 'row1', + 'row2', + 'row3', + 'row4', + 'row5' + ] + expected = [ + 'row1', + 'row2', + 'row3', + 'row4' + ] + cli.slicer() + self.assertEqual(list(cli.data_in), expected) + if __name__ == '__main__': unittest.main() \ No newline at end of file