"""Page number start / offset helpers.""" from docx import Document from docx.oxml.ns import qn from md2gost.page_geometry import apply_page_number_start, set_section_page_start def test_set_section_page_start(): doc = Document() section = doc.sections[0] set_section_page_start(section, 3) pg = section._sectPr.find(qn("w:pgNumType")) assert pg is not None assert pg.get(qn("w:start")) == "3" def test_apply_page_number_start_skips_front(): doc = Document() doc.add_section() # front doc.add_section() # body apply_page_number_start(doc, 2, front_sections=1) front = doc.sections[0]._sectPr.find(qn("w:pgNumType")) body = doc.sections[1]._sectPr.find(qn("w:pgNumType")) assert front is None or front.get(qn("w:start")) is None assert body is not None assert body.get(qn("w:start")) == "2" def test_apply_page_number_start_none_strips(): doc = Document() set_section_page_start(doc.sections[0], 5) apply_page_number_start(doc, None) pg = doc.sections[0]._sectPr.find(qn("w:pgNumType")) assert pg is None or pg.get(qn("w:start")) is None