Example #1
0
    def test_load_from_file_with_local_overriding_global(self):
        # The config data in the local and global files is loaded correctly.
        # The local data will override the global one
        content = '''
            [A]
            a=1
            b=c

            [B]
            b=2'''
        site_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_SITE_CFG_PATH"] = site_path
        content = '''
            [A]
            a=2
            d=e

            [D]
            c=d-1
            d=4'''
        local_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_LOCAL_CFG_PATH"] = local_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["A", "B", "D"], sorted(config.cfg.cfg))
        self.assertEqual({
            "a": "2",
            "b": "c",
            "d": "e"
        }, config.cfg.cfg.get("A"))
        self.assertEqual({"b": "2"}, config.cfg.cfg.get("B"))
        self.assertEqual({"c": "d-1", "d": "4"}, config.cfg.cfg.get("D"))
Example #2
0
    def test_load_from_file_with_local_overriding_global(self):
        # The config data in the local and global files is loaded correctly.
        # The local data will override the global one
        content = '''
            [A]
            a=1
            b=c

            [B]
            b=2'''
        site_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_SITE_CFG_PATH"] = site_path
        content = '''
            [A]
            a=2
            d=e

            [D]
            c=d-1
            d=4'''
        local_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_LOCAL_CFG_PATH"] = local_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["A", "B", "D"],
                         sorted(config.cfg.cfg))
        self.assertEqual({"a": "2", "b": "c", "d": "e"},
                         config.cfg.cfg.get("A"))
        self.assertEqual({"b": "2"}, config.cfg.cfg.get("B"))
        self.assertEqual({"c": "d-1", "d": "4"}, config.cfg.cfg.get("D"))
Example #3
0
 def test_get_with_known_section(self):
     # get() will correctly return configuration data for known sections
     content = '''
         [E]
         f=6
         g=h'''
     site_path = touch(content=textwrap.dedent(content))
     os.environ["OQ_SITE_CFG_PATH"] = site_path
     config.cfg.cfg.clear()
     config.cfg._load_from_file()
     self.assertEqual({"f": "6", "g": "h"}, config.cfg.get("E"))
Example #4
0
 def test_get_with_known_section(self):
     # get() will correctly return configuration data for known sections
     content = '''
         [E]
         f=6
         g=h'''
     site_path = touch(content=textwrap.dedent(content))
     os.environ["OQ_SITE_CFG_PATH"] = site_path
     config.cfg.cfg.clear()
     config.cfg._load_from_file()
     self.assertEqual({"f": "6", "g": "h"}, config.cfg.get("E"))
Example #5
0
 def prepare_config(self, section, data=None):
     """Set up a configuration with the given `max_mem` value."""
     if data is not None:
         data = '\n'.join("%s=%s" % item for item in data.items())
         content = """
             [%s]
             %s""" % (section, data)
     else:
         content = ""
     site_path = touch(content=textwrap.dedent(content))
     os.environ["OQ_CONFIG_FILE"] = site_path
     config.cfg.cfg.clear()
     config.cfg._load_from_file()
Example #6
0
    def test_load_from_file_with_local(self):
        # The config data in the local file is loaded correctly
        content = '''
            [C]
            c=3
            d=e

            [D]
            d=4'''
        local_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_LOCAL_CFG_PATH"] = local_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["C", "D"], sorted(config.cfg.cfg))
        self.assertEqual({"c": "3", "d": "e"}, config.cfg.cfg.get("C"))
        self.assertEqual({"d": "4"}, config.cfg.cfg.get("D"))
Example #7
0
    def test_load_from_file_with_global(self):
        # The config data in the global file is loaded correctly
        content = '''
            [A]
            a=1
            b=c

            [B]
            b=2'''
        site_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_SITE_CFG_PATH"] = site_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["A", "B"], sorted(config.cfg.cfg))
        self.assertEqual({"a": "1", "b": "c"}, config.cfg.cfg.get("A"))
        self.assertEqual({"b": "2"}, config.cfg.cfg.get("B"))
Example #8
0
    def test_load_from_file_with_local(self):
        # The config data in the local file is loaded correctly
        content = '''
            [C]
            c=3
            d=e

            [D]
            d=4'''
        local_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_LOCAL_CFG_PATH"] = local_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["C", "D"], sorted(config.cfg.cfg))
        self.assertEqual({"c": "3", "d": "e"}, config.cfg.cfg.get("C"))
        self.assertEqual({"d": "4"}, config.cfg.cfg.get("D"))
Example #9
0
    def test_load_from_file_with_global(self):
        # The config data in the global file is loaded correctly
        content = '''
            [A]
            a=1
            b=c

            [B]
            b=2'''
        site_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_SITE_CFG_PATH"] = site_path
        config.cfg.cfg.clear()
        config.cfg._load_from_file()
        self.assertEqual(["A", "B"], sorted(config.cfg.cfg))
        self.assertEqual({"a": "1", "b": "c"}, config.cfg.cfg.get("A"))
        self.assertEqual({"b": "2"}, config.cfg.cfg.get("B"))
Example #10
0
    def test_load_from_env_var(self):
        # The config data in the local file is loaded correctly
        content = '''
            [C]
            c=3
            d=e

            [D]
            d=4'''
        local_path = touch(content=textwrap.dedent(content))
        os.environ["OQ_CONFIG_FILE"] = local_path
        cfg = config._Config()
        cfg.cfg.clear()
        cfg._load_from_file()
        self.assertEqual(["C", "D"], sorted(cfg.cfg))
        self.assertEqual({"c": "3", "d": "e"}, cfg.cfg.get("C"))
        self.assertEqual({"d": "4"}, cfg.cfg.get("D"))