def test_scan_target_is_searched_for_config_if_found( self, mock_load: mock.MagicMock): mock_load.return_value = (self.data_dir / "config" / "tartufo.toml", {}) self.ctx.params["repo_path"] = str(self.data_dir / "config") config.read_pyproject_toml(self.ctx, self.param, "") mock_load.assert_called_once_with(self.data_dir / "config", "")
def test_file_error_is_raised_if_non_specified_config_file_cant_be_read( self, mock_load: mock.MagicMock): cur_dir = pathlib.Path() os.chdir(str(self.data_dir)) mock_load.side_effect = types.ConfigException("Bad TOML!") with self.assertRaisesRegex(click.FileError, "Bad TOML!") as exc: config.read_pyproject_toml(self.ctx, self.param, "") self.assertEqual(exc.exception.filename, str(self.data_dir / "tartufo.toml")) os.chdir(str(cur_dir))
def test_fully_resolved_filename_is_returned(self): cur_dir = pathlib.Path() os.chdir(str(self.data_dir / "config")) result = config.read_pyproject_toml(self.ctx, self.param, "") os.chdir(str(cur_dir)) self.assertEqual(result, str(self.data_dir / "config" / "tartufo.toml"))
def test_none_is_returned_if_file_not_found_and_none_specified( self, mock_load: mock.MagicMock): mock_load.side_effect = FileNotFoundError("No file for you!") self.assertIsNone(config.read_pyproject_toml(self.ctx, self.param, ""))
def test_file_error_is_raised_if_specified_file_not_found( self, mock_load: mock.MagicMock): mock_load.side_effect = FileNotFoundError("No file for you!") with self.assertRaisesRegex(click.FileError, "No file for you!"): config.read_pyproject_toml(self.ctx, self.param, "foobar.toml")
def test_specified_file_gets_read(self): runner = CliRunner() with runner.isolated_filesystem(): toml_file = self.data_dir / "config" / "tartufo.toml" config.read_pyproject_toml(self.ctx, self.param, str(toml_file)) self.assertEqual(self.ctx.default_map, {"regex": True})
def test_prefer_tartufo_toml_config_if_both_are_present(self): cur_dir = pathlib.Path() os.chdir(str(self.data_dir / "multiConfig")) config.read_pyproject_toml(self.ctx, self.param, "") os.chdir(str(cur_dir)) self.assertEqual(self.ctx.default_map, {"regex": True})
def test_tartufo_toml_gets_read_if_no_pyproject_toml(self): cur_dir = pathlib.Path() os.chdir(str(self.data_dir / "config")) config.read_pyproject_toml(self.ctx, self.param, "") os.chdir(str(cur_dir)) self.assertEqual(self.ctx.default_map, {"regex": True})
def test_pyproject_toml_gets_read_if_no_file_specified(self): cur_dir = pathlib.Path() os.chdir(str(self.data_dir)) config.read_pyproject_toml(self.ctx, self.param, "") os.chdir(str(cur_dir)) self.assertEqual(self.ctx.default_map, {"json": True})