Example #1
0
 def test_invalid_write_thru_flag_on_init(self):
     """
     Assert that if a non-boolean value is passed as write_thru,
     then the default write_thru is used
     """
     # setUp has initialized self.c, but we do not use it here
     c = configjson.Config(write_thru=1)
     self.assertEqual(c.writethru, c.DEFAULT_WRITE_THRU)
Example #2
0
 def setUp(self):
     # we have to use force=True in case the cfg file
     # was written by a previous test, the force True
     # forces initialization of the config to the
     # default configuration and does not read the
     # config file
     #self.c = configjson.Config(force=True)
     self.c = configjson.Config()
Example #3
0
 def test_invalid_cfgfile_on_init(self):
     """
     Assert that if a non-string value is passed as cfgfile,
     then the default cfgfile is used
     """
     # setUp has initialized self.c, but we do not use it here
     c = configjson.Config(cfgfile=True)
     self.assertEqual(os.path.basename(c.cfgfile), c.DEFAULT_CFG_FILE)
Example #4
0
 def test_cfgfile_property_getter_passed_value(self):
     """
     """
     # setUp has initialized self.c, but we do not use it here
     custom_cfg_file = CUSTOM_CFG_FILE
     c = configjson.Config(cfgfile=custom_cfg_file)
     cfg_file = c.cfgfile
     self.assertEqual(os.path.basename(cfg_file), custom_cfg_file)
Example #5
0
    def test_force_parameter(self):
        # setUp has initialized self.c
        self.c.cfg = D
        self.c.write()
        from_file_sys = self.c.read()

        self.c = configjson.Config(force=True)

        self.assertEqual(self.c.cfg, self.c.DEFAULT_CFG_DICT)
Example #6
0
 def test_invalid_force_flag_on_init(self):
     """
     Assert that if a non-boolean value is passed as force,
     then the default force is used.
     """
     # setUp has initialized self.c, but we do not use it here
     c = configjson.Config(force=1)
     # if the non default value of force had been used,
     # then the cfg would be the devault
     self.assertEqual(c._force, c.DEFAULT_FORCE)
Example #7
0
    def test_invalid_cfg_on_init(self):
        """
        Assert that if a non-dictionary value is passed as cfg,
        then the default cfg is used
        """
        # setUp has initialized self.c, but we do not use it here
        # cfg should be a dictionary, expect cfg to take on its default value
        c = configjson.Config(cfgdict=[1, 2, 3])

        self.assertEqual(c.cfg, c.DEFAULT_CFG_DICT)
Example #8
0
    def test_custom_exception_cfgfile_names_a_dir_not_a_file(self):
        dir_cfg = os.path.abspath(DIR_CFG_FILE)
        if not os.path.exists(dir_cfg):
            os.makedirs(dir_cfg)

        try:
            d = configjson.Config(cfgfile=dir_cfg)
        except ConfigFileNamesDirException:
            self.assertRaises(ConfigFileNamesDirException)
        else:
            should_not_get_here_should_have_asserted_earlier = True
            self.assertFalse(should_not_get_here_should_have_asserted_earlier)
Example #9
0
    def test_write_thru_enabled_via_constructor(self):
        """
        Test that the write thru feature is disabled by default.
        The self.c.cfg in memory does not match what is on the file system.
        """
        # setUp has initialized self.c, cut we do not use it in this test
        self.c = configjson.Config(write_thru=True)

        # this is now in memory and in the file system
        self.c.cfg = {'width': 12}
        s = self.c.cfg
        # read what c.cfg is in the file system
        # remember that read() returns c.cfg as
        # updated from the file system
        e = self.c.read()

        self.assertEqual(e, {'width': 12})
        self.assertEqual(self.c.cfg, {'width': 12})
        self.assertTrue(s == self.c.cfg)
Example #10
0
 def test_init_passing_in_a_cfg(self):
     """
     """
     # setUp has initialized self.c, but we do not use it here
     c = configjson.Config(cfgdict={'width': 12, 'height': 92}, force=True)
     self.assertEqual(c.cfg, {'width': 12, 'height': 92})