def test_validate_bad_field(self): badch = tuple(c for c in string.punctuation + string.digits) notnames = ( '1a', 'a.b', 'a-b', '&a', 'a++', ) + badch tests = [ ('id', ()), # Any non-empty str is okay. ('vartype', ()), # Any non-empty str is okay. ] seen = set() for field, invalid in tests: for value in invalid: seen.add(value) with self.subTest(f'{field}={value!r}'): static = Variable(**self.VALID_KWARGS) static = static._replace(**{field: value}) with self.assertRaises(ValueError): static.validate() for field, invalid in tests: valid = seen - set(invalid) for value in valid: with self.subTest(f'{field}={value!r}'): static = Variable(**self.VALID_KWARGS) static = static._replace(**{field: value}) static.validate() # This does not fail.
def test_validate_missing_field(self): for field in Variable._fields: with self.subTest(field): static = Variable(**self.VALID_KWARGS) static = static._replace(**{field: None}) with self.assertRaises(TypeError): static.validate()