Repository navigation
fix(ledger): stop a logger with no ledger named from writing into a stray ./buscado.tsv #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -621,6 +621,42 @@ def test_import_maps_columns_and_synonyms_and_needs_proof(self): | |
| [('familysearch', 'hit'), ('gazeta', 'none'), ('bvph', 'unproven')]) | ||
| self.assertEqual(rows[0]['agent'], 'import') | ||
|
|
||
| def test_a_write_with_no_ledger_named_never_creates_one(self): | ||
| # A logger run without $GWT_LEDGER put a lane's rows in a stray ./buscado.tsv of the folder it ran from, and | ||
| # its rerun was refused as already logged: an add or import-tsv that names no ledger must not create one. | ||
| src = os.path.join(self.dir.name, 'old-log.tsv') | ||
| write(src, 'who\twhere\twhat\toutcome\n' 'Ana Zorvalo\tgaceta\tedicto 1902\tnegative\n') | ||
| add = ('add', '--person', 'Ana Zorvalo', '--source', 'gaceta', '--query', 'edicto 1902', '--result', 'hit', | ||
| '--agent', 'lane-1') | ||
| imp = ('import-tsv', src, '--map', 'person_key=who,source=where,query=what,result=outcome') | ||
| work = os.path.join(self.dir.name, 'elsewhere') | ||
| os.makedirs(work) | ||
| cwd = os.getcwd() | ||
| env = {k: v for k, v in os.environ.items() if k not in ('GWT_LEDGER', 'GWT_LEDGER_DIR')} | ||
| with mock.patch.dict(os.environ, env, clear=True): # a lane's own variables must not leak in | ||
| os.chdir(work) | ||
| try: | ||
| for argv in (add, imp): | ||
| err = io.StringIO() | ||
| with redirect_stderr(err): | ||
| code, _ = run(*argv) | ||
| self.assertEqual(code, 2, argv[0]) | ||
| self.assertFalse(os.path.exists('buscado.tsv'), argv[0]) | ||
| self.assertIn(os.path.join(os.path.realpath(work), 'buscado.tsv') + ' does not exist', err.getvalue()) | ||
|
Comment on lines
+639
to
+645
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test unnamed writes to lane files. The test does not check either command with Add cases for
|
||
| self.assertIn('nothing written', err.getvalue()) | ||
| # a ./buscado.tsv that already exists is still the default ledger, as before | ||
| write('buscado.tsv', '\t'.join(L.COLUMNS) + '\n') | ||
| self.assertEqual(run(*add)[0], 0) | ||
| self.assertEqual(len(L.read_rows('buscado.tsv')), 1) | ||
|
Comment on lines
+647
to
+650
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test imports into an existing default ledger. The existing-file case tests only
|
||
| finally: | ||
| os.chdir(cwd) | ||
| # naming the ledger, by flag or by $GWT_LEDGER, still creates it | ||
| named = os.path.join(work, 'named.tsv') | ||
| self.assertEqual(run('--ledger', named, *add)[0], 0) | ||
| os.environ['GWT_LEDGER'] = os.path.join(work, 'by-env.tsv') | ||
| self.assertEqual(run(*add)[0], 0) | ||
| self.assertTrue(os.path.exists(named) and os.path.exists(os.path.join(work, 'by-env.tsv'))) | ||
|
|
||
| def test_import_checks_each_control_like_add(self): | ||
| bad = os.path.join(self.dir.name, 'bad.txt') | ||
| write(bad, 'control\tcontrol\t--name x\t0 read, want at least 3\tSHORT\n') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length of output: 3747
Script executed:
Repository: GeiserX/gramps-web-toolkit
Length of output: 41998
Web query:
Python 3 built-in open append mode creates file if it does not exist official documentationResult:
Script executed:
Repository: GeiserX/gramps-web-toolkit
Length of output: 16607
Open the unnamed ledger without creating it.
If another process removes
buscado.tsvafterstraychecks it,addorimport-tsvcan recreate it and report success. Open the unnamed ledger without creation and return exit 2 if it is missing. Preserve creation for explicitly named and lane ledgers.Ruff (0.17.1)
[warning] 831-834: Missing explicit
returnat the end of function able to return non-NonevalueAdd explicit
returnstatement(RET503)
[warning] 833-834: Use format specifiers instead of percent format
Replace with format specifiers
(UP031)