Spaces:
Runtime error
Runtime error
File size: 1,386 Bytes
74d4552 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Reference loader: read the (single-sheet) master via streaming, skip a title banner
above the headers, and not choke on a complex workbook. Multi-sheet selection is via the
explicit `sheet=` arg (a picker is a future enhancement); the default is the first sheet."""
import io
import openpyxl
from app.refdata import load_reference_xlsx
def _wb_bytes():
wb = openpyxl.Workbook()
master = wb.active
master.title = "Master"
master.append(["Client master — do not edit"]) # title banner above the headers
master.append(["Sr. No.", "Customer Name", "Partner", "Industry"])
master.append([1, "Acme Foods Limited", "Asha", "FMCG"])
master.append([2, "Zentron Robotics Inc", "Ben", "Robotics"])
extra = wb.create_sheet("Extra")
extra.append(["junk", "data"])
buf = io.BytesIO()
wb.save(buf)
return buf.getvalue()
def test_loads_first_sheet_and_skips_title_banner():
ref = load_reference_xlsx(_wb_bytes(), "master")
assert ref["columns"][:2] == ["Sr. No.", "Customer Name"] # first sheet, banner row skipped
assert len(ref["rows"]) == 2
assert ref["rows"][0]["Customer Name"] == "Acme Foods Limited"
assert ref["rows"][0]["Partner"] == "Asha"
def test_explicit_sheet_overrides_default():
ref = load_reference_xlsx(_wb_bytes(), "master", sheet="Extra")
assert ref["columns"] == ["junk", "data"]
|