Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/nid_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def main(argv=None):
requested_nids = "--nid" in requested_options
if requested_nids and requested_options & {"--name", "--symbol"}:
parser.error("--name/--symbol cannot be combined with --nid")
if requested_options & {"--name", "--symbol"} and not args.name:
parser.error("--name/--symbol requires at least one symbol name")
if args.name:
rows = [{"name": name, "nid": compute_nid(name)} for name in args.name]
if args.json:
Expand Down
15 changes: 15 additions & 0 deletions tools/tests/test_nid_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def test_annotations_do_not_change_hash_inputs(self):
self.assertEqual(nid_names.load_db(cache), {nid: "sceExample"})

class NidArgumentTests(unittest.TestCase):
def test_missing_name_values_fail_before_database_or_tree_access(self):
for arguments in (("--name",), ("--symbol", "--json"), ("--na", "--db", "unused.csv")):
with self.subTest(arguments=arguments), contextlib.redirect_stderr(io.StringIO()) as errors, \
contextlib.redirect_stdout(io.StringIO()) as output, \
patch.object(nid_names, "load_db") as database, \
patch.object(nid_names, "collect_unknowns") as sources:
with self.assertRaises(SystemExit) as exited:
nid_names.main(list(arguments))
self.assertEqual(exited.exception.code, 2)
self.assertIn("requires at least one symbol name", errors.getvalue())
self.assertEqual(output.getvalue(), "")
database.assert_not_called()
sources.assert_not_called()


options = ["-h", "--help", "--db", "--nid", "--json"]

def test_name_and_nid_modes_conflict_even_with_empty_filters(self):
Expand Down
Loading