forked from admin/miem_workers
fix: make council source checksum reproducible across platforms
This commit is contained in:
1 parent
74f32a3e67
commit
76bcb0db35
10 files changed
+43
-13
No files matched your search
@@ -30,7 +30,7 @@ def test_prepared_reference_preserves_quoted_fields_metadata_and_matching(tmp_pa
|
||||
data = prepare_reference(source)
|
||||
assert source.read_bytes() == before
|
||||
assert data['source_rows'] == 3
|
||||
assert data['source_sha256'] == hashlib.sha256(before).hexdigest()
|
||||
assert data['source_sha256'] == hashlib.sha256(before.replace(b'\r\n', b'\n')).hexdigest()
|
||||
assert data['by_author'] == {'другой автор': [0], 'елкин петр': [0]}
|
||||
record = data['publications'][0]
|
||||
assert record['title'] == 'Quoted; title\ncontinuation'
|
||||
@@ -100,3 +100,25 @@ def test_converter_does_not_replace_output_when_input_is_invalid(tmp_path):
|
||||
same = subprocess.run([sys.executable, 'scripts/prepare_council_articles.py', str(source), '--output', str(source)],
|
||||
capture_output=True, text=True)
|
||||
assert same.returncode != 0 and source.read_text(encoding='utf8') == 'Wrong header\nvalue\n'
|
||||
|
||||
|
||||
def test_preparation_is_identical_for_lf_and_crlf_sources(tmp_path):
|
||||
lf_dir = tmp_path / 'lf'
|
||||
crlf_dir = tmp_path / 'crlf'
|
||||
lf_dir.mkdir()
|
||||
crlf_dir.mkdir()
|
||||
lf = lf_dir / 'source.csv'
|
||||
crlf = crlf_dir / 'source.csv'
|
||||
write_csv(crlf, [{'Название публикации': 'Multiline\npublication', 'Год': '2024',
|
||||
'Авторы НИУ ВШЭ': 'Author; Coauthor', 'Квартиль scopus': 'Q1'}])
|
||||
canonical = crlf.read_bytes().replace(b'\r\n', b'\n')
|
||||
lf.write_bytes(canonical)
|
||||
crlf.write_bytes(canonical.replace(b'\n', b'\r\n'))
|
||||
before = crlf.read_bytes()
|
||||
from_lf = prepare_reference(lf)
|
||||
from_crlf = prepare_reference(crlf)
|
||||
assert from_lf == from_crlf
|
||||
assert from_crlf['source_sha256'] == hashlib.sha256(canonical).hexdigest()
|
||||
assert from_crlf['source_hash_eol'] == 'LF'
|
||||
assert from_crlf['publications'][0]['title'] == 'Multiline\npublication'
|
||||
assert crlf.read_bytes() == before
|
||||
Reference in new issue
Block a user