예제 #1
0
def test_validator_requirement_multiple(tmp_path):
    """'requirement' param: multiple files."""
    testfile1 = tmp_path / 'testfile1'
    testfile1.touch()
    testfile2 = tmp_path / 'testfile2'
    testfile2.touch()

    validator = Validator()
    resp = validator.validate_requirement([testfile1, testfile2])
    assert resp == [testfile1, testfile2]
예제 #2
0
def test_validator_entrypoint_simple(tmp_path):
    """'entrypoint' param: simple validation."""
    tmp_path = pathlib.Path(
        str(tmp_path))  # comparisons below don't work well in Py3.5
    testfile = tmp_path / 'testfile'
    testfile.touch(mode=0o777)

    validator = Validator()
    resp = validator.validate_entrypoint(testfile)
    assert resp == testfile
예제 #3
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)
예제 #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
예제 #5
0
def test_validator_requirement_absolutized(tmp_path, monkeypatch):
    """'requirement' param: check it's made absolute."""
    # change dir to the temp one, where we will have the reqs file
    testfile = tmp_path / 'reqs.txt'
    testfile.touch()
    monkeypatch.chdir(tmp_path)

    validator = Validator()
    resp = validator.validate_requirement([pathlib.Path('reqs.txt')])
    assert resp == [testfile]
예제 #6
0
def test_validator_from_isdir(tmp_path):
    """'from' param: checks that the directory is really that."""
    testfile = tmp_path / 'testfile'
    testfile.touch()

    validator = Validator()
    expected_msg = "the charm directory is not really a directory: '{}'".format(
        testfile)
    with pytest.raises(CommandError, match=expected_msg):
        validator.validate_from(testfile)
예제 #7
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)
예제 #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()
    resp = validator.validate_entrypoint(pathlib.Path('dirX/file.py'))
    assert resp == testfile
예제 #9
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
예제 #10
0
def test_validator_from_absolutized(tmp_path, monkeypatch):
    """'from' param: check it's made absolute."""
    # change dir to the temp one, where we will have the 'dir1/dir2' tree
    dir1 = tmp_path / 'dir1'
    dir1.mkdir()
    dir2 = dir1 / 'dir2'
    dir2.mkdir()
    monkeypatch.chdir(tmp_path)

    validator = Validator()
    resp = validator.validate_from(pathlib.Path('dir1/dir2'))
    assert resp == dir2
예제 #11
0
def test_validator_entrypoint_exec(tmp_path):
    """'entrypoint' param: checks that the file is executable."""
    tmp_path = pathlib.Path(
        str(tmp_path))  # comparisons below don't work well in Py3.5
    testfile = tmp_path / 'testfile'
    testfile.touch(mode=0o444)

    validator = Validator()
    expected_msg = "the charm entry point must be executable: '{}'".format(
        testfile)
    with pytest.raises(CommandError, match=expected_msg):
        validator.validate_entrypoint(testfile)
예제 #12
0
def test_validator_requirement_expanded(tmp_path):
    """'requirement' param: expands the user-home prefix."""
    fake_home = tmp_path / 'homedir'
    fake_home.mkdir()

    requirement = fake_home / 'requirements.txt'
    requirement.touch(0o230)

    validator = Validator()

    with patch.dict(os.environ, {'HOME': str(fake_home)}):
        resp = validator.validate_requirement([pathlib.Path('~/requirements.txt')])
    assert resp == [requirement]
예제 #13
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()

    with patch.dict(os.environ, {'HOME': str(fake_home)}):
        resp = validator.validate_entrypoint(pathlib.Path('~/testfile'))
    assert resp == testfile
예제 #14
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
예제 #15
0
def test_validator_from_default():
    """'from' param: default value."""
    validator = Validator()
    resp = validator.validate_from(None)
    assert resp == pathlib.Path('.').absolute()
예제 #16
0
def test_validator_from_simple(tmp_path):
    """'from' param: simple validation and setting in Validation."""
    validator = Validator()
    resp = validator.validate_from(tmp_path)
    assert resp == tmp_path
    assert validator.basedir == tmp_path
예제 #17
0
def test_validator_requirement_exist():
    """'requirement' param: checks that the file exists."""
    validator = Validator()
    expected_msg = "the requirements file was not found: '/not_really_there.txt'"
    with pytest.raises(CommandError, match=expected_msg):
        validator.validate_requirement([pathlib.Path('/not_really_there.txt')])
예제 #18
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 == []
예제 #19
0
def test_validator_entrypoint_exist():
    """'entrypoint' param: checks that the file exists."""
    validator = Validator()
    expected_msg = "the charm entry point was not found: '/not_really_there.py'"
    with pytest.raises(CommandError, match=expected_msg):
        validator.validate_entrypoint(pathlib.Path('/not_really_there.py'))
예제 #20
0
def test_validator_from_exist():
    """'from' param: checks that the directory exists."""
    validator = Validator()
    expected_msg = "the charm directory was not found: '/not_really_there'"
    with pytest.raises(CommandError, match=expected_msg):
        validator.validate_from(pathlib.Path('/not_really_there'))
예제 #21
0
def test_validator_from_expanded():
    """'from' param: expands the user-home prefix."""
    validator = Validator()
    resp = validator.validate_from(pathlib.Path('~'))
    assert resp == pathlib.Path.home()