import os import feed_file_exporter as ffe from constants import files as file_consts def test_slice_rows_edge_cases(): assert list(ffe.slice_rows([], 3)) == [] assert list(ffe.slice_rows([1], 5)) == [[1]] assert list(ffe.slice_rows([1, 2, 3, 4], 2)) == [[1, 2], [3, 4]] assert list(ffe.slice_rows([1, 2, 3, 4, 5], 2)) == [[1, 2], [3, 4], [5]] def test_write_rows_to_file_writes_correct_order(tmp_path): outdir = str(tmp_path) fn = 'sample.txt' rows = { 'header': 'H', 'body': ['B1', 'B2'], 'tail': 'T', } path = ffe.write_rows_to_file(outdir, fn, rows) assert os.path.exists(path) with open(path, 'r', encoding='utf8') as f: content = f.read() expected = 'H' + file_consts.LINE_TERMINATOR expected += 'B1' + file_consts.LINE_TERMINATOR expected += 'B2' + file_consts.LINE_TERMINATOR expected += 'T' # Normalize line endings for robust assertion across platforms assert content.replace('\r\n', '\n') == expected.replace('\r\n', '\n')