Skip to content

Commit 324f09c

Browse files
committed
fix: Update tests to handle openpyxl color format and ContextVar
- Fix header color assertion to check only RGB values (not alpha channel) - Remove ContextVar mock as it cannot be patched in Python 3.11+ - All 17 tests now passing successfully
1 parent 46ef86d commit 324f09c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

tests/test_excel_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def test_header_formatting(self, excel_store):
143143
# Check header formatting
144144
header_cell = excel_store.contents_sheet.cell(row=1, column=1)
145145
assert header_cell.font.bold is True
146-
assert header_cell.fill.start_color.rgb == "FF366092"
146+
# RGB color may have different prefix (00 or FF), check the actual color part
147+
assert header_cell.fill.start_color.rgb[-6:] == "366092"
147148

148149
def test_empty_sheets_removed(self, excel_store):
149150
"""Test that empty sheets are removed on flush"""

tests/test_store_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def test_create_mongodb_store(self):
5151
assert isinstance(store, XhsMongoStoreImplement)
5252

5353
@patch('config.SAVE_DATA_OPTION', 'excel')
54-
@patch('var.crawler_type_var.get', return_value='search')
55-
def test_create_excel_store(self, mock_crawler_type):
54+
def test_create_excel_store(self):
5655
"""Test creating Excel store"""
56+
# ContextVar cannot be mocked, so we test with actual value
5757
store = XhsStoreFactory.create_store()
5858
assert isinstance(store, XhsExcelStoreImplement)
5959

0 commit comments

Comments
 (0)