Beispiel #1
0
def test_validator_requirement_simple(tmp_path):
    """'requirement' param: simple validation."""
    testfile = tmp_path / 'testfile'
    testfile.touch()

    validator = Validator()
    resp = validator.validate_requirement([testfile])
    assert resp == [testfile]
Beispiel #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 == []
Beispiel #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]
Beispiel #4
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]
Beispiel #5
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]
Beispiel #6
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]
Beispiel #7
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')])
Beispiel #8
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 == []