Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 3
0
    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"
Ejemplo n.º 4
0
    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")
Ejemplo n.º 5
0
    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")
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 9
0
    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"
        ))
Ejemplo n.º 10
0
    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"
        )
Ejemplo n.º 11
0
    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"
        ))
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
    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())
Ejemplo n.º 14
0
    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())
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 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())
Ejemplo n.º 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))
Ejemplo n.º 19
0
    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
Ejemplo n.º 20
0
    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)
Ejemplo n.º 21
0
    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)
Ejemplo n.º 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")
Ejemplo n.º 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!")
Ejemplo n.º 24
0
    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")
Ejemplo n.º 25
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")

        self.assertTrue(
            str(cm.exception).startswith(
                "The following error has occurred while handling the option"))
Ejemplo n.º 26
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")

        self.assertTrue(str(cm.exception).startswith(
            "The following error has occurred while handling the option"
        ))
Ejemplo n.º 27
0
    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"
Ejemplo n.º 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")
Ejemplo n.º 29
0
    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")
Ejemplo n.º 30
0
 def read_test(self):
     parser = create_parser()
     self._read_content(parser)
Ejemplo n.º 31
0
 def test_read(self):
     parser = create_parser()
     self._read_content(parser)
Ejemplo n.º 32
0
 def read_test(self):
     parser = create_parser()
     self._read_content(parser)