Exemple #1
0
    def get_config(self, *, defaults=False):
        class Config(configparser.RawConfigParser):
            def write_conf(self):
                write_config_helper(self)

        def write_config_helper(conf):
            with open(self.pyrex_conf, "w") as f:
                conf.write(f)

        config = Config()
        if os.path.exists(self.pyrex_conf) and not defaults:
            config.read(self.pyrex_conf)
        else:
            config.read_string(pyrex.read_default_config(True))

            # Setup the config suitable for testing
            config["config"]["image"] = self.test_image
            config["config"]["engine"] = self.provider
            config["config"]["buildlocal"] = "0"
            config["config"]["pyrextag"] = (os.environ.get(
                TEST_PREBUILT_TAG_ENV_VAR, "") or "ci-test")
            config["run"]["bind"] += " " + self.build_dir
            config["imagebuild"]["buildcommand"] = "%s --provider=%s %s" % (
                os.path.join(PYREX_ROOT, "ci", "build_image.py"),
                self.provider,
                self.test_image,
            )

        return config
Exemple #2
0
    def test_default_ini_image(self):
        # Tests that the default image specified in pyrex.ini is valid
        config = pyrex.Config()
        config.read_string(pyrex.read_default_config(True))

        self.assertIn(config["config"]["image"],
                      (image for (image, _) in TEST_IMAGES))
Exemple #3
0
    def get_config(self, *, defaults=False, pyrex_conf=None):
        if pyrex_conf is None:
            pyrex_conf = self.pyrex_conf

        class Config(configparser.RawConfigParser):
            def write_conf(self):
                write_config_helper(self)

        def write_config_helper(conf):
            with open(pyrex_conf, "w") as f:
                conf.write(f)

        config = Config()
        if os.path.exists(pyrex_conf) and not defaults:
            config.read(pyrex_conf)
        else:
            config.read_string(pyrex.read_default_config(True))

            # Setup the config suitable for testing
            config["config"]["dockerimage"] = self.test_image
            config["config"]["dockerpath"] = self.dockerpath
            config["config"]["buildlocal"] = "0"
            config["config"]["pyrextag"] = (os.environ.get(
                TEST_PREBUILT_TAG_ENV_VAR, "") or "ci-test")

        return config
Exemple #4
0
    def get_config(self, defaults=False):
        class Config(configparser.RawConfigParser):
            def write_conf(self):
                write_config_helper(self)

        def write_config_helper(conf):
            with open(self.pyrex_conf, 'w') as f:
                conf.write(f)

        config = Config()
        if os.path.exists(self.pyrex_conf) and not defaults:
            config.read(self.pyrex_conf)
        else:
            config.read_string(pyrex.read_default_config(True))

            # Setup the config suitable for testing
            config['config']['dockerimage'] = self.test_image

            prebuilt_tag = os.environ.get(TEST_PREBUILT_TAG_ENV_VAR, '')
            if prebuilt_tag:
                config['config']['pyrextag'] = prebuilt_tag
                config['config']['buildlocal'] = '0'
            else:
                # Always build the latest image locally for testing. Use a tag that
                # isn't present on docker hub so that any attempt to pull it fails
                config['config']['pyrextag'] = 'ci-test'
                config['config']['buildlocal'] = '1'

        return config
Exemple #5
0
    def get_config(self, defaults=False):
        class Config(configparser.RawConfigParser):
            def write_conf(self):
                write_config_helper(self)

        def write_config_helper(conf):
            with open(self.pyrex_conf, 'w') as f:
                conf.write(f)

        config = Config()
        if os.path.exists(self.pyrex_conf) and not defaults:
            config.read(self.pyrex_conf)
        else:
            config.read_string(pyrex.read_default_config(True))
        return config
Exemple #6
0
    def test_pyrex_mkconfig(self):
        out_file = os.path.join(self.build_dir, "temp-pyrex.ini")
        cmd = [os.path.join(PYREX_ROOT, "pyrex.py"), "mkconfig"]

        output = self.assertSubprocess(
            cmd + [out_file], capture=True, cwd=self.build_dir
        )
        self.assertEqual(output, out_file)

        output = self.assertSubprocess(cmd, capture=True)
        self.assertEqual(output, pyrex.read_default_config(False).rstrip())

        with open(out_file, "r") as f:
            self.assertEqual(f.read().rstrip(), output)

        self.assertSubprocess(cmd + [out_file], cwd=self.build_dir, returncode=1)
Exemple #7
0
    def test_default_ini_image(self):
        # Tests that the default image specified in pyrex.ini is valid
        config = configparser.RawConfigParser()
        config.read_string(pyrex.read_default_config(True))

        self.assertIn(config["config"]["dockerimage"], TEST_IMAGES)