first commint
This commit is contained in:
53
test_detect_filled_cells.py
Normal file
53
test_detect_filled_cells.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import tempfile
|
||||
import os
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.styles import PatternFill
|
||||
|
||||
from detect_filled_cells import detect_colored_cells
|
||||
|
||||
|
||||
def create_sample_workbook(path):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = 'Sheet1'
|
||||
|
||||
# A1: solid green with full ARGB
|
||||
ws['A1'].fill = PatternFill(start_color='FF00B050', end_color='FF00B050', fill_type='solid')
|
||||
ws['A1'].value = 'block'
|
||||
|
||||
# B2: solid blue with 6-digit rgb (should be treated as FF+rgb)
|
||||
ws['B2'].fill = PatternFill(start_color='00B0F0', end_color='00B0F0', fill_type='solid')
|
||||
ws['B2'].value = 'water'
|
||||
|
||||
# C3: no fill
|
||||
ws['C3'].value = 'empty'
|
||||
|
||||
wb.save(path)
|
||||
|
||||
|
||||
def run_test():
|
||||
tf = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
|
||||
tf.close()
|
||||
try:
|
||||
create_sample_workbook(tf.name)
|
||||
print(f"Saved sample workbook to: {tf.name}")
|
||||
|
||||
results = detect_colored_cells(tf.name, sheet_name='Sheet1')
|
||||
print('Detected colored cells:')
|
||||
for r in results:
|
||||
print(r)
|
||||
|
||||
assert any(r['coordinate'] == 'A1' for r in results), 'A1 should be detected'
|
||||
assert any(r['coordinate'] == 'B2' for r in results), 'B2 should be detected'
|
||||
assert all(r['coordinate'] != 'C3' for r in results), 'C3 should not be detected'
|
||||
|
||||
print('\nTest passed')
|
||||
finally:
|
||||
try:
|
||||
os.unlink(tf.name)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_test()
|
||||
Reference in New Issue
Block a user