def test_list_commands_converts_underscore_to_hyphen( self, mock_dir: mock.MagicMock): mock_dir.glob.return_value = [ FakeFile("foo_bar.py"), ] commands = cli.TartufoCLI().list_commands(None) # type: ignore self.assertEqual(commands, ["foo-bar"])
def test_list_commands_excludes_init_py(self, mock_dir: mock.MagicMock): mock_dir.glob.return_value = [ FakeFile("__init__.py"), FakeFile("foo.py"), FakeFile("bar.py"), ] commands = cli.TartufoCLI().list_commands(None) # type: ignore self.assertNotIn("__init__", commands)
def test_list_commands_strips_file_extensions(self, mock_dir: mock.MagicMock): mock_dir.glob.return_value = [ FakeFile("foo.py"), FakeFile("bar.py"), FakeFile("baz.py"), ] commands = cli.TartufoCLI().list_commands(None) # type: ignore self.assertEqual(commands, ["foo", "bar", "baz"])
def test_list_commands_only_looks_at_python_files( self, mock_dir: mock.MagicMock): mock_dir.glob.return_value = [ FakeFile("__init__.py"), FakeFile("foo.py"), FakeFile("bar.py"), ] cli.TartufoCLI().list_commands(None) # type: ignore mock_dir.glob.assert_called_once_with("*.py")
def test_get_command_fails_gracefully_on_invalid_commands(self): command = cli.TartufoCLI().get_command(None, "bar") # type: ignore self.assertEqual(command, None)
def test_get_command_returns_main_attribute_from_command_modules(self): command = cli.TartufoCLI().get_command(None, "foo") # type: ignore self.assertEqual(command, command_foo.main)