def image_name_spec(self): """ Image names are constrained by what docker wants And by the fact that option_merge means we can't have keys with dots in them. Otherwise if we have something like "ubuntu14.04" as an image, then when we do {images.ubuntu14.04.image_name} it'll look for config["images"]["ubuntu14"]["04"]["image_name"] instead of config["images"]["ubuntu14.04"]["image_name"] which is unlikely to be the desired result. """ return valid_string_spec( validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))
def container_name_spec(self): """Just needs to be ascii""" return valid_string_spec(validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))
res2 = va.either_keys(["one", "two"], ["three", "four"]).normalise(self.meta, val2) self.assertEqual(res1, val1) self.assertEqual(res2, val2) describe TestCase, "no_whitesapce": before_each: self.meta = mock.Mock(name="meta") it "Sets up a whitespace regex": fake_compile = mock.Mock(name="fake_compile") compiled_regex = mock.Mock(name="compiled_regex") with mock.patch("re.compile", fake_compile): fake_compile.return_value = compiled_regex validator = va.no_whitespace() self.assertIs(validator.regex, compiled_regex) fake_compile.assert_called_once_with("\s+") it "has a regex that finds whitespace": validator = va.no_whitespace() assert validator.regex.search(" \t\n") assert validator.regex.search("\t\n") assert validator.regex.search("\n") assert validator.regex.search("\n ") assert not validator.regex.match("d") it "complains if the value has whitespace": val = "adf " with self.fuzzyAssertRaisesError(BadSpecValue, "Expected no whitespace", meta=self.meta, val=val):
it "Lets the val through if it has atleast one choice": val = {"one": 1} self.assertEqual(va.has_either(["one", "two"]).normalise(self.meta, val), val) describe TestCase, "no_whitesapce": before_each: self.meta = mock.Mock(name="meta") it "Sets up a whitespace regex": fake_compile = mock.Mock(name="fake_compile") compiled_regex = mock.Mock(name="compiled_regex") with mock.patch("re.compile", fake_compile): fake_compile.return_value = compiled_regex validator = va.no_whitespace() self.assertIs(validator.regex, compiled_regex) fake_compile.assert_called_once_with("\s+") it "has a regex that finds whitespace": validator = va.no_whitespace() assert validator.regex.search(" \t\n") assert validator.regex.search("\t\n") assert validator.regex.search("\n") assert validator.regex.search("\n ") assert not validator.regex.match("d") it "complains if the value has whitespace": val = "adf " with self.fuzzyAssertRaisesError(BadSpecValue, "Expected no whitespace", meta=self.meta, val=val):
def container_name_spec(self): """Just needs to be ascii""" return valid_string_spec( validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))