From ed4822f2eb63d7c09e1d7325b0c0aada91c56c78 Mon Sep 17 00:00:00 2001 From: David Vincent Fischer Date: Mon, 15 Sep 2025 16:08:56 +0200 Subject: [PATCH] Update tests/test_styles_csv_loader.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/test_styles_csv_loader.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/test_styles_csv_loader.py b/tests/test_styles_csv_loader.py index bcd4453..3a2de0d 100644 --- a/tests/test_styles_csv_loader.py +++ b/tests/test_styles_csv_loader.py @@ -45,19 +45,26 @@ class TestStylesCSVLoader(unittest.TestCase): self.assertEqual(cinematic_style[1], 'low quality, blurry, amateur') def test_load_invalid_csv(self): - """Test loading an invalid CSV file (missing columns).""" + """Test loading an invalid CSV file (missing columns). Should return an error dictionary.""" styles = StylesCSVLoader.load_styles_csv(self.invalid_csv_path) - # NOTE: Due to the current implementation, when an exception occurs during - # the dictionary comprehension (line 31), the styles variable is left as - # the parsed list from line 29-30, not the error dictionary. - # This is actually a bug in the original code, but we test the current behavior. - self.assertIsInstance(styles, list) - - # Verify it contains the parsed CSV rows - self.assertGreater(len(styles), 0) - self.assertIn('Missing Column', styles[0]) - + # The correct behavior: should return a dict with an error message + self.assertIsInstance(styles, dict) + error_key = list(styles.keys())[0] + self.assertIn('Error loading styles.csv', error_key) + self.assertIsInstance(styles[error_key], str) + + def test_load_invalid_csv_buggy_behavior(self): + """[BUG DOCUMENTATION] Current buggy behavior: returns a list instead of error dict for invalid CSV. + Remove this test once the bug in styles_csv_loader.py is fixed.""" + styles = StylesCSVLoader.load_styles_csv(self.invalid_csv_path) + # This documents the buggy behavior for regression tracking. + if isinstance(styles, list): + self.assertGreater(len(styles), 0) + self.assertIn('Missing Column', styles[0]) + else: + # If bug is fixed, this test should be removed. + self.skipTest("Bug fixed: loader returns error dict instead of list.") def test_load_nonexistent_csv(self): """Test loading a nonexistent CSV file.""" styles = StylesCSVLoader.load_styles_csv(self.nonexistent_csv_path)