def test_has_one_config_file(tmp_path, config_file, caplog): """There is a root dir (setup.py) and a single config file.""" project = ProjectMock(tmp_path, pyproject_toml=False, setup_py=True) project.save_file("local.toml", "").save_file( config_file, """ [tool.nitpick] style = ["local.toml"] cache = "forever" """, ).api_check(offline=True) path = project.root_dir / config_file assert project.nitpick_instance.project.read_configuration( ) == Configuration(path, ["local.toml"], "forever") assert f"Config file: reading from {path}" in caplog.text
def test_generic_ini_with_missing_header(tmp_path): """A generic .ini with a missing header should raise a violation.""" expected_generic_ini = """ this_key_is_invalid = for a generic .ini (it should always have a section) [your-section] your_number = 200 your_string = value """ project = ProjectMock(tmp_path) project.save_file("generic.ini", expected_generic_ini).style(""" ["generic.ini".your-section] your_string = "value" your_number = 100 """).api_check_then_fix( Fuss( False, "generic.ini", Violations.PARSING_ERROR.code, ": parsing error (MissingSectionHeaderError): File contains no section headers.\n" f"file: {project.path_for('generic.ini')!r}, line: 1\n" "'this_key_is_invalid = for a generic .ini (it should always have a section)\\n'", )).assert_file_contents("generic.ini", expected_generic_ini)
def test_has_multiple_config_files(tmp_path, caplog): """There is a root dir (setup.py) and multiple config files.""" project = ProjectMock(tmp_path, pyproject_toml=True, setup_py=True) project.save_file("local_nit.toml", "").save_file("local_pyproj.toml", "").save_file( DOT_NITPICK_TOML, """ [tool.nitpick] style = ["local_nit.toml"] cache = "never" """, ).save_file( PYPROJECT_TOML, """ [tool.nitpick] style = ["local_pyproj.toml"] cache = "forever" """, ).api_check(offline=True) assert project.nitpick_instance.project.read_configuration( ) == Configuration(project.root_dir / DOT_NITPICK_TOML, ["local_nit.toml"], "never") assert f"Config file: reading from {project.root_dir / DOT_NITPICK_TOML}" in caplog.text assert f"Config file: ignoring existing {project.root_dir / PYPROJECT_TOML}" in caplog.text