Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
    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
Пример #4
0
 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))
Пример #5
0
 def test_invalid(self):
     # should raise an assertion error
     validate_update_envvar("VALUE",
                            5,
                            variable_model=self.schema,
                            prefix=self.prefix)
Пример #6
0
 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))