示例#1
0
    def testSavesRawDataCorrectly(self):
        with temp.AutoTempFilePath() as path:
            p = config_parser.YamlConfigFileParser(path)
            p.SaveData({"Section1": {"test": "val2"}})

            with open(path, "r") as fd:
                self.assertEqual(fd.read(), "Section1:\n  test: val2\n")
示例#2
0
    def testGenClientConfig_ignoreBuilderContext(self):
        with test_lib.PreserveConfig():
            # Define a secondary config with special values for the ClientBuilder
            # context.
            str_override = """
        Test Context:
          Client.labels: [label0, label1]
          ClientBuilder Context:
            Client.labels: [build-label0, build-label1]
      """
            parser = config_parser.YamlConfigFileParser("")
            override = parser.RawDataFromBytes(str_override.encode("utf-8"))
            config.CONFIG.MergeData(override)
            # Sanity-check that the secondary config was merged into the global
            # config.
            self.assertEqual(config.CONFIG["Client.labels"],
                             ["label0", "label1"])

            context = [
                "Test Context", "ClientBuilder Context", "Client Context"
            ]
            str_client_config = build_helpers.GetClientConfig(context)
            client_config = parser.RawDataFromBytes(
                str_client_config.encode("utf-8"))
            # Settings particular to the ClientBuilder context should not carry over
            # into the generated client config.
            self.assertEqual(client_config["Client.labels"],
                             ["label0", "label1"])
示例#3
0
    def testRaisesWhenFileIsNotAccessible(self):
        with temp.AutoTempFilePath() as path:
            with open(path, "w") as fd:
                fd.write("")
            os.chmod(path, stat.S_IWUSR)

            with self.assertRaises(config_parser.ReadDataPermissionError):
                p = config_parser.YamlConfigFileParser(path)
                p.ReadData()
示例#4
0
    def testReadsRawDataCorrectly(self):
        with temp.AutoTempFilePath() as path:
            with open(path, "w") as fd:
                fd.write("""
Section1:
  test: val2
""")

            p = config_parser.YamlConfigFileParser(path)
            self.assertEqual(p.ReadData(), {"Section1": {"test": "val2"}})
示例#5
0
    def testGenClientConfig(self):
        with test_lib.ConfigOverrider({"Client.build_environment":
                                       "test_env"}):

            data = build_helpers.GetClientConfig(["Client Context"],
                                                 validate=True)

            parser = config_parser.YamlConfigFileParser("")
            raw_data = parser.RawDataFromBytes(data.encode("utf-8"))

            self.assertIn("Client.deploy_time", raw_data)
示例#6
0
 def GetConfigFromTemplate(self, template_path):
   """Apply build.yaml settings from the template."""
   with zipfile.ZipFile(template_path) as template_zip:
     build_yaml = None
     for name in template_zip.namelist():
       if name.endswith("build.yaml"):
         build_yaml = name
         break
     if not build_yaml:
       raise RuntimeError("Couldn't find build.yaml in %s" % template_path)
     with template_zip.open(build_yaml) as buildfile:
       repack_config = config.CONFIG.CopyConfig()
       parser = config_parser.YamlConfigFileParser("")
       config_data = parser.ReadDataFromFD(buildfile)
       self.Validate(config_data, template_path)
       repack_config.MergeData(config_data)
   return repack_config
示例#7
0
 def testReturnsEmptyDictWhenFileIsMissing(self):
     with temp.AutoTempFilePath() as path:
         p = config_parser.YamlConfigFileParser(path)
         self.assertEqual(p.ReadData(), {})
示例#8
0
 def testCopyPointsToTheSameConfigPath(self):
     p = config_parser.YamlConfigFileParser("foo/bar")
     p_copy = p.Copy()
     self.assertNotEqual(p, p_copy)
     self.assertEqual(p_copy.config_path, "foo/bar")
示例#9
0
 def testRaisesWhenSavingAndConfigPathEmpty(self):
     p = config_parser.YamlConfigFileParser("")
     with self.assertRaises(config_parser.SaveDataPathNotSpecifiedError):
         p.SaveData({})