Esempio n. 1
0
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
Esempio n. 2
0
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 == []
Esempio n. 3
0
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]
Esempio n. 4
0
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
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
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
Esempio n. 10
0
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 == []