def test_schema_defaultvalue(self): # should re-set the value to the default validate_update_envvar("VALUE", None, variable_model=self.schema, prefix=self.prefix) self.assertEqual(os.environ[self.prefix + "VALUE"], str(self.default))
def test_schema_nonnullvalue(self): # should update the value where conditions pass validate_update_envvar("VALUE", self.value, variable_model=self.schema, prefix=self.prefix) self.assertEqual(os.environ[self.prefix + "VALUE"], str(self.value))
def __setattr__(self, name, value): """ Custom setattr to set environment variables. Setting attributes with or without the specified prefix should set the appropriate prefixed environment variable. """ if hasattr(self, "spec"): prefix = getattr(self, "prefix", "") dump = self.dump() name = remove_prefix(name, prefix) if name in self.spec: validate_update_envvar( name, value=value, prefix=self.prefix, force_active=self.force_active, variable_model=self.spec, formatter=self.output_formatter, ) else: # other object attributes self.__dict__[name] = value else: self.__dict__[name] = value
def test_set_and_remove(self): validate_update_envvar("VALUE", 52, variable_model=self.schema, prefix=self.prefix) validate_update_envvar("VALUE", None, variable_model=self.schema, prefix=self.prefix) self.assertEqual(os.environ[self.prefix + "VALUE"], str(self.default))
def test_invalid(self): # should raise an assertion error validate_update_envvar("VALUE", 5, variable_model=self.schema, prefix=self.prefix)
def test_default(self): # should update the value validate_update_envvar("VALUE", self.value, prefix=self.prefix) self.assertEqual(os.environ[self.prefix + "VALUE"], str(self.value))