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 = "Charm directory is not really a directory: '{}'".format(testfile) with pytest.raises(CommandError, match=expected_msg): validator.validate_from(testfile)
def test_validator_from_simple(tmp_path): """'from' param: simple validation and setting in Validation.""" tmp_path = pathlib.Path( str(tmp_path)) # comparisons below don't work well in Py3.5 validator = Validator() resp = validator.validate_from(tmp_path) assert resp == tmp_path assert validator.basedir == tmp_path
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
def test_validator_from_default(): """'from' param: default value.""" validator = Validator() resp = validator.validate_from(None) assert resp == pathlib.Path('.').absolute()
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
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'))
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()