Exemple #1
0
    def _compare_profile_files(self,
                               file_name,
                               other_file_name,
                               ignored_sections=()):
        parser = create_parser()
        read_config(parser, os.path.join(PROFILE_DIR, file_name))

        other_parser = create_parser()
        read_config(other_parser, os.path.join(PROFILE_DIR, other_file_name))

        # Ignore the specified and profile-related sections.
        ignored_sections += ("Profile", "Profile Detection")

        sections = set(parser.sections()).difference(ignored_sections)
        other_sections = set(
            other_parser.sections()).difference(ignored_sections)

        # Otherwise, the defined sections should be the same.
        assert sections == other_sections

        for section in sections:
            # The defined options should be the same.
            assert parser.options(section) == other_parser.options(section)

            for key in parser.options(section):
                # The values of the options should be the same.
                assert parser.get(section,
                                  key) == other_parser.get(section, key)
Exemple #2
0
    def _compare_product_files(self,
                               file_name,
                               other_file_name,
                               ignored_sections=()):
        parser = create_parser()
        read_config(parser, os.path.join(PRODUCT_DIR, file_name))

        other_parser = create_parser()
        read_config(other_parser, os.path.join(PRODUCT_DIR, other_file_name))

        # Ignore the specified and product-related sections.
        ignored_sections += ("Product", "Base Product")

        sections = set(parser.sections()).difference(ignored_sections)
        other_sections = set(
            other_parser.sections()).difference(ignored_sections)

        # Otherwise, the defined sections should be the same.
        self.assertEqual(sections, other_sections)

        for section in sections:
            # The defined options should be the same.
            self.assertEqual(parser.options(section),
                             other_parser.options(section))

            for key in parser.options(section):
                # The values of the options should be the same.
                self.assertEqual(parser.get(section, key),
                                 other_parser.get(section, key))
    def test_invalid_read(self):
        parser = create_parser()

        with pytest.raises(ConfigurationFileError) as cm:
            read_config(parser, "nonexistent/path/to/file")

        assert cm.value._filename == "nonexistent/path/to/file"
    def invalid_read_test(self):
        parser = create_parser()

        with self.assertRaises(ConfigurationFileError) as cm:
            read_config(parser, "nonexistent/path/to/file")

        self.assertEqual(cm.exception._filename, "nonexistent/path/to/file")
    def invalid_read_test(self):
        parser = create_parser()

        with self.assertRaises(ConfigurationFileError) as cm:
            read_config(parser, "nonexistent/path/to/file")

        self.assertEqual(cm.exception._filename, "nonexistent/path/to/file")
Exemple #6
0
    def load_product(self, config_path):
        """Load information about a product from the given configuration file.

        :param config_path: a path to a configuration file
        :raises: ConfigurationError if a product cannot be loaded
        """
        # Set up the parser.
        parser = create_parser()
        self._create_section(parser, "Product")
        self._create_section(parser, "Base Product")

        # Read the product sections.
        read_config(parser, config_path)
        key = self._read_section(parser, "Product")
        base = self._read_section(parser, "Base Product")

        # Check the product.
        if not key.product_name:
            raise ConfigurationError("The product name is not specified.")

        if key in self._products:
            raise ConfigurationError("The product {} was already loaded.".format(key))

        # Check the base product.
        if not base.product_name:
            base = None

        # Add the product.
        log.info("Found %s at %s.", key, config_path)
        self._products[key] = ProductData(base, config_path)
Exemple #7
0
    def load_product(self, config_path):
        """Load information about a product from the given configuration file.

        :param config_path: a path to a configuration file
        :raises: ConfigurationError if a product cannot be loaded
        """
        # Set up the parser.
        parser = create_parser()
        self._create_section(parser, "Product")
        self._create_section(parser, "Base Product")

        # Read the product sections.
        read_config(parser, config_path)
        key = self._read_section(parser, "Product")
        base = self._read_section(parser, "Base Product")

        # Check the product.
        if not key.product_name:
            raise ConfigurationError("The product name is not specified.")

        if key in self._products:
            raise ConfigurationError(
                "The product {} was already loaded.".format(key))

        # Check the base product.
        if not base.product_name:
            base = None

        # Add the product.
        log.info("Found %s at %s.", key, config_path)
        self._products[key] = ProductData(base, config_path)
Exemple #8
0
    def __init__(self):
        """Initialize the configuration."""
        self._sources = []
        self._parser = create_parser()

        self._anaconda = AnacondaSection("Anaconda", self.get_parser())
        self._storage = StorageSection("Storage", self.get_parser())
        self._services = ServicesSection("Services", self.get_parser())
    def invalid_write_test(self):
        parser = create_parser()

        with self.assertRaises(ConfigurationFileError) as cm:
            write_config(parser, "nonexistent/path/to/file")

        self.assertEqual(cm.exception._filename, "nonexistent/path/to/file")
        self.assertTrue(str(cm.exception).startswith(
            "The following error has occurred while handling the configuration file"
        ))
    def test_invalid_write(self):
        parser = create_parser()

        with pytest.raises(ConfigurationFileError) as cm:
            write_config(parser, "nonexistent/path/to/file")

        assert cm.value._filename == "nonexistent/path/to/file"
        assert str(cm.value).startswith(
            "The following error has occurred while handling the configuration file"
        )
    def invalid_write_test(self):
        parser = create_parser()

        with self.assertRaises(ConfigurationFileError) as cm:
            write_config(parser, "nonexistent/path/to/file")

        self.assertEqual(cm.exception._filename, "nonexistent/path/to/file")
        self.assertTrue(str(cm.exception).startswith(
            "The following error has occurred while handling the configuration file"
        ))
    def test_get(self):
        parser = create_parser()
        self._read_content(parser)

        assert get_option(parser, "Main", "string") == "Hello"
        assert get_option(parser, "Main", "integer") == "1"
        assert get_option(parser, "Main", "boolean") == "False"

        assert get_option(parser, "Main", "string", str) == "Hello"
        assert get_option(parser, "Main", "integer", int) == 1
        assert get_option(parser, "Main", "boolean", bool) == False
    def write_test(self):
        parser = create_parser()
        self._read_content(parser)

        with tempfile.NamedTemporaryFile("r+") as f:
            # Write the config file.
            write_config(parser, f.name)
            f.flush()

            # Check the config file.
            self.assertEqual(f.read().strip(), self._content.strip())
    def write_test(self):
        parser = create_parser()
        self._read_content(parser)

        with tempfile.NamedTemporaryFile("r+") as f:
            # Write the config file.
            write_config(parser, f.name)
            f.flush()

            # Check the config file.
            self.assertEqual(f.read().strip(), self._content.strip())
    def get_test(self):
        parser = create_parser()
        self._read_content(parser)

        self.assertEqual(get_option(parser, "Main", "string"), "Hello")
        self.assertEqual(get_option(parser, "Main", "integer"), "1")
        self.assertEqual(get_option(parser, "Main", "boolean"), "False")

        self.assertEqual(get_option(parser, "Main", "string", str), "Hello")
        self.assertEqual(get_option(parser, "Main", "integer", int), 1)
        self.assertEqual(get_option(parser, "Main", "boolean", bool), False)
    def get_test(self):
        parser = create_parser()
        self._read_content(parser)

        self.assertEqual(get_option(parser, "Main", "string"), "Hello")
        self.assertEqual(get_option(parser, "Main", "integer"), "1")
        self.assertEqual(get_option(parser, "Main", "boolean"), "False")

        self.assertEqual(get_option(parser, "Main", "string", str), "Hello")
        self.assertEqual(get_option(parser, "Main", "integer", int), 1)
        self.assertEqual(get_option(parser, "Main", "boolean", bool), False)
Exemple #17
0
    def __init__(self):
        """Initialize the configuration."""
        self._sources = []
        self._parser = create_parser()

        self._anaconda = AnacondaSection("Anaconda", self.get_parser())
        self._system = InstallationSystem("Installation System",
                                          self.get_parser())
        self._target = InstallationTarget("Installation Target",
                                          self.get_parser())
        self._storage = StorageSection("Storage", self.get_parser())
        self._services = ServicesSection("Services", self.get_parser())
Exemple #18
0
    def _compare_product_files(self, file_name, other_file_name):
        parser = create_parser()
        read_config(parser, os.path.join(PRODUCT_DIR, file_name))

        other_parser = create_parser()
        read_config(other_parser, os.path.join(PRODUCT_DIR, other_file_name))

        # The defined sections should be the same.
        self.assertEqual(parser.sections(), other_parser.sections())

        for section in parser.sections():
            # Skip the product-related sections.
            if section in ("Product", "Base Product"):
                continue

            # The defined options should be the same.
            self.assertEqual(parser.options(section), other_parser.options(section))

            for key in parser.options(section):
                # The values of the options should be the same.
                self.assertEqual(parser.get(section, key), other_parser.get(section, key))
    def test_set(self):
        parser = create_parser()
        self._read_content(parser)

        set_option(parser, "Main", "string", "Hi")
        set_option(parser, "Main", "integer", 2)
        set_option(parser, "Main", "boolean", True)

        assert get_option(parser, "Main", "string") == "Hi"
        assert get_option(parser, "Main", "integer") == "2"
        assert get_option(parser, "Main", "boolean") == "True"

        assert get_option(parser, "Main", "string", str) == "Hi"
        assert get_option(parser, "Main", "integer", int) == 2
        assert get_option(parser, "Main", "boolean", bool) == True
    def set_test(self):
        parser = create_parser()
        self._read_content(parser)

        set_option(parser, "Main", "string", "Hi")
        set_option(parser, "Main", "integer", 2)
        set_option(parser, "Main", "boolean", True)

        self.assertEqual(get_option(parser, "Main", "string"), "Hi")
        self.assertEqual(get_option(parser, "Main", "integer"), "2")
        self.assertEqual(get_option(parser, "Main", "boolean"), "True")

        self.assertEqual(get_option(parser, "Main", "string", str), "Hi")
        self.assertEqual(get_option(parser, "Main", "integer", int), 2)
        self.assertEqual(get_option(parser, "Main", "boolean", bool), True)
    def set_test(self):
        parser = create_parser()
        self._read_content(parser)

        set_option(parser, "Main", "string", "Hi")
        set_option(parser, "Main", "integer", 2)
        set_option(parser, "Main", "boolean", True)

        self.assertEqual(get_option(parser, "Main", "string"), "Hi")
        self.assertEqual(get_option(parser, "Main", "integer"), "2")
        self.assertEqual(get_option(parser, "Main", "boolean"), "True")

        self.assertEqual(get_option(parser, "Main", "string", str), "Hi")
        self.assertEqual(get_option(parser, "Main", "integer", int), 2)
        self.assertEqual(get_option(parser, "Main", "boolean", bool), True)
Exemple #22
0
    def invalid_set_test(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid option.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Main", "unknown", "value")

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "unknown")

        # Invalid section.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Unknown", "unknown", "value")

        self.assertEqual(cm.exception._section, "Unknown")
        self.assertEqual(cm.exception._option, "unknown")
Exemple #23
0
    def load_from_file(self, config_path):
        """Load information about a profile from the given configuration file.

        :param config_path: a path to a configuration file
        :raises: ConfigurationError if a profile cannot be loaded
        """
        # Set up the parser.
        parser = create_parser()
        self._create_profile_section(parser)
        self._create_profile_detection_section(parser)

        # Read the profile sections.
        self.config_path = config_path
        read_config(parser, config_path)

        self._read_profile_section(parser)
        self._read_profile_detection_section(parser)

        if not self.profile_id:
            raise ConfigurationError("The profile id is not specified!")
    def test_invalid_set(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid option.
        with pytest.raises(ConfigurationDataError) as cm:
            set_option(parser, "Main", "unknown", "value")

        assert cm.value._section == "Main"
        assert cm.value._option == "unknown"

        # Invalid section.
        with pytest.raises(ConfigurationDataError) as cm:
            set_option(parser, "Unknown", "unknown", "value")

        assert cm.value._section == "Unknown"
        assert cm.value._option == "unknown"

        assert str(cm.value).startswith(
            "The following error has occurred while handling the option")
    def invalid_set_test(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid option.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Main", "unknown", "value")

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "unknown")

        # Invalid section.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Unknown", "unknown", "value")

        self.assertEqual(cm.exception._section, "Unknown")
        self.assertEqual(cm.exception._option, "unknown")

        self.assertTrue(
            str(cm.exception).startswith(
                "The following error has occurred while handling the option"))
    def invalid_set_test(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid option.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Main", "unknown", "value")

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "unknown")

        # Invalid section.
        with self.assertRaises(ConfigurationDataError) as cm:
            set_option(parser, "Unknown", "unknown", "value")

        self.assertEqual(cm.exception._section, "Unknown")
        self.assertEqual(cm.exception._option, "unknown")

        self.assertTrue(str(cm.exception).startswith(
            "The following error has occurred while handling the option"
        ))
    def test_invalid_get(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid value.
        with pytest.raises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "string", bool)

        assert cm.value._section == "Main"
        assert cm.value._option == "string"

        # Invalid option.
        with pytest.raises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "unknown")

        assert cm.value._section == "Main"
        assert cm.value._option == "unknown"

        # Invalid section.
        with pytest.raises(ConfigurationDataError) as cm:
            get_option(parser, "Unknown", "unknown")

        assert cm.value._section == "Unknown"
        assert cm.value._option == "unknown"
Exemple #28
0
    def test_invalid_get(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid value.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "string", bool)

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "string")

        # Invalid option.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "unknown")

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "unknown")

        # Invalid section.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Unknown", "unknown")

        self.assertEqual(cm.exception._section, "Unknown")
        self.assertEqual(cm.exception._option, "unknown")
    def invalid_get_test(self):
        parser = create_parser()
        self._read_content(parser)

        # Invalid value.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "string", bool)

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "string")

        # Invalid option.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Main", "unknown")

        self.assertEqual(cm.exception._section, "Main")
        self.assertEqual(cm.exception._option, "unknown")

        # Invalid section.
        with self.assertRaises(ConfigurationDataError) as cm:
            get_option(parser, "Unknown", "unknown")

        self.assertEqual(cm.exception._section, "Unknown")
        self.assertEqual(cm.exception._option, "unknown")
 def read_test(self):
     parser = create_parser()
     self._read_content(parser)
Exemple #31
0
 def test_read(self):
     parser = create_parser()
     self._read_content(parser)
 def read_test(self):
     parser = create_parser()
     self._read_content(parser)