From d81537f1bfe108604026e81f8d0e41812393efee Mon Sep 17 00:00:00 2001 From: PeninsulaInd Date: Sat, 18 Oct 2025 14:53:15 -0500 Subject: [PATCH] Story 2.1 finished --- tests/unit/test_cora_parser.py | 48 ++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/tests/unit/test_cora_parser.py b/tests/unit/test_cora_parser.py index c36b436..08f0693 100644 --- a/tests/unit/test_cora_parser.py +++ b/tests/unit/test_cora_parser.py @@ -208,8 +208,8 @@ class TestCORAParserExtractStrategicOverview: assert result["lsi_density"] == 0.05 assert result["spintax_related_search_terms"] == "{term1|term2|term3}" - def test_extract_strategic_overview_defaults_when_no_sheet(self, tmp_path): - """Test default values when sheet not available""" + def test_extract_strategic_overview_missing_sheet_raises_error(self, tmp_path): + """Test error raised when Strategic Overview sheet not available""" test_file = tmp_path / "test.xlsx" test_file.touch() @@ -218,11 +218,8 @@ class TestCORAParserExtractStrategicOverview: with patch('openpyxl.load_workbook', return_value=mock_workbook): parser = CORAParser(str(test_file)) - result = parser.extract_strategic_overview() - - assert result["word_count"] == 1250 - assert result["term_frequency"] == 3 - assert result["related_search_density"] is None + with pytest.raises(CORAParseError, match="Required sheet 'Strategic Overview' not found"): + parser.extract_strategic_overview() class TestCORAParserExtractStructureMetrics: @@ -253,8 +250,8 @@ class TestCORAParserExtractStructureMetrics: assert result["h1_exact"] == 1 assert result["h2_total"] == 1 - def test_extract_structure_metrics_defaults_when_no_sheet(self, tmp_path): - """Test default values when sheet not available""" + def test_extract_structure_metrics_missing_sheet_raises_error(self, tmp_path): + """Test error raised when Structure sheet not available""" test_file = tmp_path / "test.xlsx" test_file.touch() @@ -263,10 +260,8 @@ class TestCORAParserExtractStructureMetrics: with patch('openpyxl.load_workbook', return_value=mock_workbook): parser = CORAParser(str(test_file)) - result = parser.extract_structure_metrics() - - assert result["title_exact_match"] is None - assert result["h1_exact"] is None + with pytest.raises(CORAParseError, match="Required sheet 'Structure' not found"): + parser.extract_structure_metrics() class TestCORAParserExtractEntities: @@ -431,12 +426,37 @@ class TestCORAParserParse: test_file.touch() mock_workbook = Mock() - mock_workbook.sheetnames = [] + mock_workbook.sheetnames = ["Strategic Overview", "Structure"] mock_workbook.close = Mock() + mock_so_sheet = Mock() + def mock_so_getitem(self, cell_ref): + mock_cell = Mock() + values = {"B5": "test", "D24": 1000, "D31": 2} + mock_cell.value = values.get(cell_ref) + return mock_cell + mock_so_sheet.__getitem__ = mock_so_getitem + + mock_structure_sheet = Mock() + def mock_structure_getitem(self, cell_ref): + mock_cell = Mock() + mock_cell.value = None + return mock_cell + mock_structure_sheet.__getitem__ = mock_structure_getitem + + def mock_wb_getitem(self, sheet_name): + if sheet_name == "Strategic Overview": + return mock_so_sheet + elif sheet_name == "Structure": + return mock_structure_sheet + return None + + mock_workbook.__getitem__ = mock_wb_getitem + with patch('openpyxl.load_workbook', return_value=mock_workbook): parser = CORAParser(str(test_file)) result = parser.parse(custom_anchor_text=["anchor1", "anchor2"]) assert result["custom_anchor_text"] == ["anchor1", "anchor2"] + assert result["main_keyword"] == "test"