def test_validator_entrypoint_simple(tmp_path): """'entrypoint' param: simple validation.""" testfile = tmp_path / 'testfile' testfile.touch(mode=0o777) validator = Validator() validator.basedir = tmp_path resp = validator.validate_entrypoint(testfile) assert resp == testfile
def test_validator_requirement_default_present_not_readable(tmp_path): """'requirement' param: default value when a requirements.txt is there but not readable.""" default_requirement = tmp_path / 'requirements.txt' default_requirement.touch(0o230) validator = Validator() validator.basedir = tmp_path resp = validator.validate_requirement(None) assert resp == []
def test_validator_requirement_default_present_ok(tmp_path): """'requirement' param: default value when a requirements.txt is there and readable.""" default_requirement = tmp_path / "requirements.txt" default_requirement.touch() validator = Validator() validator.basedir = tmp_path resp = validator.validate_requirement(None) assert resp == [default_requirement]
def test_validator_entrypoint_default(tmp_path): """'entrypoint' param: default value.""" default_entrypoint = tmp_path / 'src' / 'charm.py' default_entrypoint.parent.mkdir() default_entrypoint.touch(mode=0o777) validator = Validator() validator.basedir = tmp_path resp = validator.validate_entrypoint(None) assert resp == default_entrypoint
def test_validator_entrypoint_exec(tmp_path): """'entrypoint' param: checks that the file is executable.""" testfile = tmp_path / 'testfile' testfile.touch(mode=0o444) validator = Validator() validator.basedir = tmp_path expected_msg = "Charm entry point must be executable: '{}'".format(testfile) with pytest.raises(CommandError, match=expected_msg): validator.validate_entrypoint(testfile)
def test_validator_entrypoint_inside_project(tmp_path): """'entrypoint' param: checks that it's part of the project.""" project_dir = tmp_path / 'test-project' testfile = tmp_path / 'testfile' testfile.touch(mode=0o777) validator = Validator() validator.basedir = project_dir expected_msg = "Charm entry point must be inside the project: '{}'".format(testfile) with pytest.raises(CommandError, match=expected_msg): validator.validate_entrypoint(testfile)
def test_validator_entrypoint_default(tmp_path): """'entrypoint' param: default value.""" tmp_path = pathlib.Path( str(tmp_path)) # comparisons below don't work well in Py3.5 default_entrypoint = tmp_path / 'src' / 'charm.py' default_entrypoint.parent.mkdir() default_entrypoint.touch(mode=0o777) validator = Validator() validator.basedir = tmp_path resp = validator.validate_entrypoint(None) assert resp == default_entrypoint
def test_validator_entrypoint_absolutized(tmp_path, monkeypatch): """'entrypoint' param: check it's made absolute.""" # change dir to the temp one, where we will have the 'dirX/file.py' stuff dirx = tmp_path / 'dirX' dirx.mkdir() testfile = dirx / 'file.py' testfile.touch(mode=0o777) monkeypatch.chdir(tmp_path) validator = Validator() validator.basedir = tmp_path resp = validator.validate_entrypoint(pathlib.Path('dirX/file.py')) assert resp == testfile
def test_validator_entrypoint_expanded(tmp_path): """'entrypoint' param: expands the user-home prefix.""" fake_home = tmp_path / 'homedir' fake_home.mkdir() testfile = fake_home / 'testfile' testfile.touch(mode=0o777) validator = Validator() validator.basedir = tmp_path with patch.dict(os.environ, {'HOME': str(fake_home)}): resp = validator.validate_entrypoint(pathlib.Path('~/testfile')) assert resp == testfile
def test_validator_requirement_default_missing(tmp_path): """'requirement' param: default value when no requirements.txt is there.""" validator = Validator() validator.basedir = tmp_path resp = validator.validate_requirement(None) assert resp == []