diff --git a/tests/test_csv_loader.py b/tests/test_csv_loader.py index 41d983c..ebdd5fb 100644 --- a/tests/test_csv_loader.py +++ b/tests/test_csv_loader.py @@ -2,6 +2,7 @@ from unittest import TestCase from unittest.mock import patch, mock_open +from file_test import OPEN, PATH_EXISTS, PATH_ISFILE from pystreamapi.loaders import csv file_content = """ @@ -9,15 +10,16 @@ 1,2.0 a,b """ +file_path = 'path/to/data.csv' class TestCSVLoader(TestCase): def test_csv_loader(self): - with (patch('builtins.open', mock_open(read_data=file_content)), - patch('os.path.exists', return_value=True), - patch('os.path.isfile', return_value=True)): - data = csv('path/to/data.csv') + with (patch(OPEN, mock_open(read_data=file_content)), + patch(PATH_EXISTS, return_value=True), + patch(PATH_ISFILE, return_value=True)): + data = csv(file_path) self.assertEqual(len(data), 2) self.assertEqual(data[0].attr1, 1) self.assertIsInstance(data[0].attr1, int) @@ -27,10 +29,10 @@ def test_csv_loader(self): self.assertIsInstance(data[1].attr1, str) def test_csv_loader_with_casting_disabled(self): - with (patch('builtins.open', mock_open(read_data=file_content)), - patch('os.path.exists', return_value=True), - patch('os.path.isfile', return_value=True)): - data = csv('path/to/data.csv', cast_types=False) + with (patch(OPEN, mock_open(read_data=file_content)), + patch(PATH_EXISTS, return_value=True), + patch(PATH_ISFILE, return_value=True)): + data = csv(file_path, cast_types=False) self.assertEqual(len(data), 2) self.assertEqual(data[0].attr1, '1') self.assertIsInstance(data[0].attr1, str) @@ -40,26 +42,26 @@ def test_csv_loader_with_casting_disabled(self): self.assertIsInstance(data[1].attr1, str) def test_csv_loader_is_iterable(self): - with (patch('builtins.open', mock_open(read_data=file_content)), - patch('os.path.exists', return_value=True), - patch('os.path.isfile', return_value=True)): - data = csv('path/to/data.csv') + with (patch(OPEN, mock_open(read_data=file_content)), + patch(PATH_EXISTS, return_value=True), + patch(PATH_ISFILE, return_value=True)): + data = csv(file_path) self.assertEqual(len(list(iter(data))), 2) def test_csv_loader_with_custom_delimiter(self): - with (patch('builtins.open', mock_open(read_data=file_content.replace(",", ";"))), - patch('os.path.exists', return_value=True), - patch('os.path.isfile', return_value=True)): - data = csv('path/to/data.csv', delimiter=';') + with (patch(OPEN, mock_open(read_data=file_content.replace(",", ";"))), + patch(PATH_EXISTS, return_value=True), + patch(PATH_ISFILE, return_value=True)): + data = csv(file_path, delimiter=';') self.assertEqual(len(data), 2) self.assertEqual(data[0].attr1, 1) self.assertIsInstance(data[0].attr1, int) def test_csv_loader_with_empty_file(self): - with (patch('builtins.open', mock_open(read_data="")), - patch('os.path.exists', return_value=True), - patch('os.path.isfile', return_value=True)): - data = csv('path/to/data.csv') + with (patch(OPEN, mock_open(read_data="")), + patch(PATH_EXISTS, return_value=True), + patch(PATH_ISFILE, return_value=True)): + data = csv(file_path) self.assertEqual(len(data), 0) def test_csv_loader_with_invalid_path(self): diff --git a/tests/test_error_handler.py b/tests/test_error_handler.py index 80aaef8..22e4bc4 100644 --- a/tests/test_error_handler.py +++ b/tests/test_error_handler.py @@ -108,7 +108,7 @@ def test_remove_sentinels_no_sentinels(self): def test_sentinel_eq(self): s1 = Sentinel() s2 = Sentinel() - self.assertTrue(s1 == s2) + self.assertEqual(s1, s2) def test_sentinel_eq_false(self): s1 = Sentinel() @@ -118,7 +118,7 @@ def test_sentinel_eq_false(self): def test_sentinel_ne(self): s1 = Sentinel() s2 = object() - self.assertTrue(s1 != s2) + self.assertNotEqual(s1, s2) def test_sentinel_ne_false(self): s1 = Sentinel() diff --git a/tests/test_json_loader.py b/tests/test_json_loader.py index 7532af4..2051843 100644 --- a/tests/test_json_loader.py +++ b/tests/test_json_loader.py @@ -18,7 +18,7 @@ } ] """ - +file_path = 'path/to/data.json' class TestJsonLoader(TestCase): @@ -26,7 +26,7 @@ def test_json_loader_from_file(self): with (patch(OPEN, mock_open(read_data=file_content)), patch(PATH_EXISTS, return_value=True), patch(PATH_ISFILE, return_value=True)): - data = json('path/to/data.json') + data = json(file_path) self.assertEqual(len(data), 2) self.assertEqual(data[0].attr1, 1) self.assertIsInstance(data[0].attr1, int) @@ -39,14 +39,14 @@ def test_json_loader_is_iterable(self): with (patch(OPEN, mock_open(read_data=file_content)), patch(PATH_EXISTS, return_value=True), patch(PATH_ISFILE, return_value=True)): - data = json('path/to/data.json') + data = json(file_path) self.assertEqual(len(list(iter(data))), 2) def test_json_loader_with_empty_file(self): with (patch(OPEN, mock_open(read_data="")), patch(PATH_EXISTS, return_value=True), patch(PATH_ISFILE, return_value=True)): - data = json('path/to/data.json') + data = json(file_path) self.assertEqual(len(data), 0) def test_json_loader_with_invalid_path(self): @@ -69,4 +69,4 @@ def test_json_loader_from_string(self): def test_json_loader_from_empty_string(self): with self.assertRaises(JSONDecodeError): - self.assertEqual(len(json('', read_from_src=True)), 0) + len(json('', read_from_src=True))