コード例 #1
0
    def testSaveLoadEmpty(self):
        config = config_lib.SiteConfig(defaults={}, site_params={})
        config_str = config.SaveConfigToString()
        loaded = config_lib.LoadConfigFromString(config_str)

        self.assertEqual(config, loaded)

        self.assertEqual(loaded.keys(), [])
        self.assertEqual(loaded._templates.keys(), [])
        self.assertEqual(loaded.GetDefault(), config_lib.DefaultSettings())
        self.assertEqual(
            loaded.params,
            config_lib.SiteParameters(config_lib.DefaultSiteParameters()))

        self.assertNotEqual(loaded.SaveConfigToString(), '')

        # Make sure we can dump debug content without crashing.
        self.assertNotEqual(loaded.DumpExpandedConfigToString(), '')
コード例 #2
0
 def testSaveLoadReload(self):
     """Make sure that loading and reloading the config is a no-op."""
     dump = self.all_configs.SaveConfigToString()
     loaded = config_lib.LoadConfigFromString(dump)
     self.assertEqual(self.all_configs, loaded)
コード例 #3
0
    def testSaveLoadComplex(self):

        # pylint: disable=line-too-long
        src_str = """{
    "_default": {
        "bar": true,
        "baz": false,
        "child_configs": [],
        "foo": false,
        "hw_tests": [],
        "nested": { "sub1": 1, "sub2": 2 }
    },
    "_site_params": {
        "site_foo": true,
        "site_bar": false
    },
    "_templates": {
       "build": {
            "baz": true
       }
    },
    "diff_build": {
        "_template": "build",
        "bar": false,
        "foo": true,
        "name": "diff_build"
    },
    "match_build": {
        "name": "match_build"
    },
    "parent_build": {
        "child_configs": [
            {
                "name": "empty_build"
            },
            {
                "bar": false,
                "name": "child_build",
                "hw_tests": [
                    "{\\n    \\"async\\": true,\\n    \\"blocking\\": false,\\n    \\"critical\\": false,\\n    \\"file_bugs\\": true,\\n    \\"max_retries\\": null,\\n    \\"minimum_duts\\": 4,\\n    \\"num\\": 2,\\n    \\"offload_failures_only\\": false,\\n    \\"pool\\": \\"bvt\\",\\n    \\"priority\\": \\"PostBuild\\",\\n    \\"retry\\": false,\\n    \\"suite\\": \\"bvt-perbuild\\",\\n    \\"suite_min_duts\\": 1,\\n    \\"timeout\\": 5400,\\n    \\"warn_only\\": false\\n}"
                ]
            }
        ],
        "name": "parent_build"
    },
    "default_name_build": {
    }
}"""

        config = config_lib.LoadConfigFromString(src_str)

        expected_defaults = config_lib.DefaultSettings()
        expected_defaults.update({
            "bar": True,
            "baz": False,
            "child_configs": [],
            "foo": False,
            "hw_tests": [],
            "nested": {
                "sub1": 1,
                "sub2": 2
            },
        })

        self.assertEqual(config.GetDefault(), expected_defaults)

        # Verify assorted stuff in the loaded config to make sure it matches
        # expectations.
        self.assertFalse(config['match_build'].foo)
        self.assertTrue(config['match_build'].bar)
        self.assertFalse(config['match_build'].baz)
        self.assertTrue(config['diff_build'].foo)
        self.assertFalse(config['diff_build'].bar)
        self.assertTrue(config['diff_build'].baz)
        self.assertTrue(config['parent_build'].bar)
        self.assertTrue(config['parent_build'].child_configs[0].bar)
        self.assertFalse(config['parent_build'].child_configs[1].bar)
        self.assertEqual(
            config['parent_build'].child_configs[1].hw_tests[0],
            config_lib.HWTestConfig(suite='bvt-perbuild',
                                    async=True,
                                    file_bugs=True,
                                    max_retries=None,
                                    minimum_duts=4,
                                    num=2,
                                    priority='PostBuild',
                                    retry=False,
                                    suite_min_duts=1))
コード例 #4
0
                                    async=True,
                                    file_bugs=True,
                                    max_retries=None,
                                    minimum_duts=4,
                                    num=2,
                                    priority='PostBuild',
                                    retry=False,
                                    suite_min_duts=1))
        self.assertEqual(config['default_name_build'].name,
                         'default_name_build')

        self.assertTrue(config.params.site_foo)
        self.assertFalse(config.params.site_bar)

        # Load an save again, just to make sure there are no changes.
        loaded = config_lib.LoadConfigFromString(config.SaveConfigToString())

        self.assertEqual(config, loaded)

        # Make sure we can dump debug content without crashing.
        self.assertNotEqual(config.DumpExpandedConfigToString(), '')

    def testChromeOsLoad(self):
        """This test compares chromeos_config to config_dump.json."""
        # If there is a test failure, the diff will be big.
        self.maxDiff = None

        src = chromeos_config.GetConfig()
        new = config_lib.LoadConfigFromFile()

        self.assertDictEqual(src.GetDefault(), new.GetDefault())