Ejemplo n.º 1
0
    def run_id(self, run_id):
        if self._maually_set_run_id:
            raise TypeError(self.RUN_ID_IS_IMMUTABLE_MSG)

        self._maually_set_run_id = True
        logging.debug('filling in run_id wildcards')
        self._run_id = datetimeutils.fill_in_datetime_strings(run_id,
                                                              today=self.today)

        Config.set_run_id(self._run_id)
Ejemplo n.º 2
0
    def test_setting_config_run_id_today(self, reset_config):
        # setting
        Config.set({"FOO": "{run_id}_{today-2:%Y%m%d}_bar", "bar": "baz"})
        assert Config._RUN_ID == None
        assert Config._TODAY == None
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="{run_id}_{today-2:%Y%m%d}_bar",
                            bar="baz")
        EXPECTED = dict(DEFAULTS, foo="{run_id}_20160418_bar", bar="baz")
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        # set today
        Config.set_today(datetime.datetime(2019, 1, 5, 10, 12, 1))
        assert Config._RUN_ID == None
        assert Config._TODAY == datetime.datetime(2019, 1, 5, 10, 12, 1)
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="{run_id}_{today-2:%Y%m%d}_bar",
                            bar="baz")
        EXPECTED = dict(DEFAULTS, foo="{run_id}_20190103_bar", bar="baz")
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        # set again; datetime wildcard should be filled in
        Config.set({"fOO": "{run_id}_{today:%Y%m%d%H}_bar", "bar": "sdfsdf"})
        assert Config._RUN_ID == None
        assert Config._TODAY == datetime.datetime(2019, 1, 5, 10, 12, 1)
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="{run_id}_{today:%Y%m%d%H}_bar",
                            bar="sdfsdf")
        EXPECTED = dict(DEFAULTS, foo="{run_id}_2019010510_bar", bar="sdfsdf")
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        # set run_id
        Config.set_run_id("abc123")
        assert Config._RUN_ID == "abc123"
        assert Config._TODAY == datetime.datetime(2019, 1, 5, 10, 12, 1)
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="{run_id}_{today:%Y%m%d%H}_bar",
                            bar="sdfsdf")
        EXPECTED = dict(DEFAULTS, foo="abc123_2019010510_bar", bar="sdfsdf")
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        # set again; datetime and run_id wildcards should be filled in
        Config.set({"foo": "FOO_{run_id}_{today:%Y%m%d%H}_bar", "bar": "zz"})
        assert Config._RUN_ID == "abc123"
        assert Config._TODAY == datetime.datetime(2019, 1, 5, 10, 12, 1)
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="FOO_{run_id}_{today:%Y%m%d%H}_bar",
                            bar="zz")
        EXPECTED = dict(DEFAULTS, foo="FOO_abc123_2019010510_bar", bar="zz")
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        # set in individual values
        Config.set(100, "bar")
        Config.set(200, "BAAAR")
        Config.set("sdfsdf{run_id}", "baz", "a")
        Config.set("{run_id}", "BAZ", "b")
        assert Config._RUN_ID == "abc123"
        assert Config._TODAY == datetime.datetime(2019, 1, 5, 10, 12, 1)
        EXPECTED_RAW = dict(DEFAULTS,
                            foo="FOO_{run_id}_{today:%Y%m%d%H}_bar",
                            bar=100,
                            baaar=200,
                            baz={
                                "a": "sdfsdf{run_id}",
                                "b": "{run_id}"
                            })
        EXPECTED = dict(DEFAULTS,
                        foo="FOO_abc123_2019010510_bar",
                        bar=100,
                        baaar=200,
                        baz={
                            "a": "sdfsdfabc123",
                            "b": "abc123"
                        })
        assert Config._RAW_CONFIG == EXPECTED_RAW
        assert Config._CONFIG == EXPECTED
        assert Config.get() == EXPECTED

        assert self._ORIGINAL_DEFAULTS == DEFAULTS
Ejemplo n.º 3
0
 def _initialize_run_id(self):
     self._maually_set_run_id = False
     # default to guid, but manual set will still be allowed
     self._run_id = str(uuid.uuid4())
     Config.set_run_id(self._run_id)