def test_no_install_empty_project() -> None: """Validates that bento does installs a config on an empty project""" context = Context(base_path=INTEGRATION / "none", is_init=True) command = InitCommand(context) with mod_file(context.config_path): context.config_path.unlink() assert not context.config_path.exists() command._install_config_if_not_exists() assert len(context.config["tools"]) == 0
def test_install_ignore_in_repo() -> None: """Validates that bento installs an ignore file if none exists""" context = Context(base_path=SIMPLE, is_init=True) command = InitCommand(context) with mod_file(context.ignore_file_path): context.ignore_file_path.unlink() command._install_ignore_if_not_exists() context = Context(base_path=SIMPLE, is_init=True) assert context.ignore_file_path.exists()
def test_install_ignore_in_repo() -> None: """Validates that bento installs an ignore file if none exists""" context = Context(base_path=SIMPLE, is_init=True) command = InitCommand(context) with util.mod_file(context.ignore_file_path): context.ignore_file_path.unlink() command._install_ignore_if_not_exists() context = Context(base_path=SIMPLE, is_init=True) ig = context.file_ignores assert "node_modules/" in ig.patterns
def test_no_install_empty_project() -> None: """Validates that bento does not install a config on an empty project""" context = Context(base_path=INTEGRATION / "none") command = InitCommand(context) # pytest.raises() does not catch SystemExit, so use try/except here try: command._install_config_if_not_exists() except SystemExit as ex: assert isinstance(ex, SystemExit) assert not context.config_path.exists()
def test_install_ignore_no_repo(tmp_path: Path, monkeypatch: MonkeyPatch) -> None: """Validates that bento installs extra ignore items when not in a git repo""" monkeypatch.chdir(tmp_path) context = Context(base_path=tmp_path, is_init=True) command = InitCommand(context) command._install_ignore_if_not_exists() context = Context(base_path=tmp_path, is_init=True) ig = context.file_ignores assert "node_modules/" in ig.patterns
def test_install_config() -> None: """Validates that bento installs a config file if none exists""" context = Context(base_path=SIMPLE, is_init=True) command = InitCommand(context) with mod_file(context.config_path): context.config_path.unlink() command._install_config_if_not_exists() cfg = context.config assert "eslint" in cfg["tools"] assert "flake8" in cfg["tools"] assert "bandit" in cfg["tools"]
def test_install_ignore_no_repo(tmp_path: Path, monkeypatch: MonkeyPatch) -> None: """Validates that bento installs extra ignore items when not in a git repo""" monkeypatch.chdir(tmp_path) context = Context(base_path=tmp_path, is_init=True) assert not context.ignore_file_path.exists() command = InitCommand(context) command._install_ignore_if_not_exists() assert context.ignore_file_path.exists() with context.ignore_file_path.open() as file: patterns = file.read() assert "node_modules/" in patterns