def test_include_remote_style_from_local_style(tmp_path): """Test include of remote style when there is only a local style.""" remote_style = "https://raw.githubusercontent.com/user/repo/branch/path/to/nitpick-style" url_with_extension = f"{remote_style}{TOML_EXTENSION}" body = """ ["tox.ini".section] key = "value" """ responses.add(responses.GET, url_with_extension, dedent(body), status=200) project = ProjectMock(tmp_path).style(f""" [nitpick.styles] include = [ "{remote_style}" ] """) project.assert_file_contents(TOX_INI, None).api_check_then_fix( Fuss(True, TOX_INI, 321, " was not found. Create it with this content:", "[section]\nkey = value")).assert_file_contents( TOX_INI, """ [section] key = value """, PYPROJECT_TOML, None, )
def test_each_builtin_style(tmp_path, datadir, builtin_style_path): """Test each built-in style (skip presets).""" style = BuiltinStyle.from_path(builtin_style_path) violations = [] name_contents = [] for filename in style.files: expected_path = datadir / style.path_from_resources_root / filename if not expected_path.exists(): # Creates empty files on datadir, to help with the task of adding new built-in styles # You just need to fill in the expected contents of each file fixture_path = Path( __file__ ).parent / "test_builtin" / style.path_from_resources_root / filename fixture_path.parent.mkdir(parents=True, exist_ok=True) fixture_path.touch(exist_ok=True) expected_contents = expected_path.read_text() code = BUILTIN_STYLE_CODES[filename] violations.append( Fuss(True, filename, code, " was not found. Create it with this content:", expected_contents)) name_contents.extend([filename, expected_contents]) violations.extend( BUILTIN_STYLE_EXTRA_VIOLATIONS.get(style.path_from_resources_root, [])) project = ProjectMock(tmp_path).save_file( DOT_NITPICK_TOML, f""" [tool.nitpick] style = "{style.py_url_without_ext}" """, ) # Run `nitpick fix` twice on the style # First time check: it should report violations and create new file(s) project.api_check_then_fix(*violations) if style.files: project.assert_file_contents(*name_contents) has_unfixed_violations = any(not fuss.fixed for fuss in violations) if has_unfixed_violations: # If some violations can't be fixed, we can't check for the second time and we must leave return # Second time check: it should not report any violation and should not change the existing file(s) project.api_check_then_fix() if style.files: project.assert_file_contents(*name_contents)