def test_remove_redundancies_material_settings(self):
        """
		Tests whether non-material settings ignore material profiles for
		redundancy checks.
		"""
        quality = optimise.Profile(settings={
            "material_bed_temperature": 60,
            "layer_height": 0.1337
        })
        material = optimise.Profile(settings={
            "material_bed_temperature": 70,
            "layer_height": 0.2337
        },
                                    filepath="/path/to/PLA.inst.cfg",
                                    subprofiles=[quality])
        variant = optimise.Profile(settings={
            "material_bed_temperature": 60,
            "layer_height": 0.1337
        },
                                   subprofiles=[material])
        optimise.remove_redundancies(variant)
        self.assertDictEqual(
            quality.settings, {"material_bed_temperature": 60},
            "Bed temperature is a material setting so it should override the material. Layer height is not a material setting so it should ignore the value in the material."
        )
    def test_remove_redundancies_empty(self):
        """
		Tests removing redundant settings with empty profiles.
		"""
        child = optimise.Profile()
        parent = optimise.Profile(subprofiles=[child])
        optimise.remove_redundancies(parent)
        self.assertDictEqual(child.settings, {},
                             "The profile should still be empty.")
    def test_remove_redundancies_root(self):
        """
		Tests removing redundant settings of the root profile.

		In the root profile, no settings are redundant.
		"""
        root = optimise.Profile(settings={"foo": "bar"})
        optimise.remove_redundancies(root)
        self.assertDictEqual(root.settings, {"foo": "bar"},
                             "The settings of the root should be untouched.")
    def test_remove_redundancies_not_redundant(self):
        """
		Tests whether it properly retains settings that are not redundant.

		The setting is not equal to the parent setting.
		"""
        child = optimise.Profile(settings={"apples": 4})
        parent = optimise.Profile(settings={"apples": 3}, subprofiles=[child])
        optimise.remove_redundancies(parent)
        self.assertDictEqual(
            child.settings, {"apples": 4},
            "The child setting differs from its parent, so it's not redundant."
        )
    def test_remove_redundancies_redundant(self):
        """
		Tests whether it removes settings that are equal to the parent setting.
		"""
        child = optimise.Profile(settings={"apples": 3})
        parent = optimise.Profile(settings={"apples": 3}, subprofiles=[child])
        optimise.remove_redundancies(parent)
        self.assertDictEqual(
            child.settings, {},
            "The child setting is equal to its parent, so it's redundant and should be removed."
        )
        self.assertDictEqual(
            parent.settings, {"apples": 3},
            "The parent setting should not get removed, since the child depends on it."
        )
    def test_remove_redundancies_mixed(self):
        """
		Tests removing redundancies where only part of the settings are
		redundant.

		It shouldn't remove all of them or none, since the settings are
		redundant, not the profiles.
		"""
        child = optimise.Profile(settings={"apples": 4, "pears": 8})
        parent = optimise.Profile(settings={
            "apples": 3,
            "pears": 8
        },
                                  subprofiles=[child])
        optimise.remove_redundancies(parent)
        self.assertDictEqual(
            child.settings, {"apples": 4},
            "Apples overrides its parent, but pears was the same as its parent so pears was redundant."
        )
    def test_remove_redundancies_grandchildren(self):
        """
		Tests removing redundant settings through multiple layers.

		If the setting gets removed in the child, that should not influence
		removing redundant settings in the grandchild.
		"""
        grandchild = optimise.Profile(settings={"apples": 3})
        child = optimise.Profile(settings={"apples": 3},
                                 subprofiles=[grandchild])
        parent = optimise.Profile(settings={"apples": 3}, subprofiles=[child])
        optimise.remove_redundancies(parent)
        self.assertDictEqual(
            grandchild.settings, {},
            "The grandchild apples=3 was the same as the child apples=3, even though the child setting was removed due to redundancy."
        )
        self.assertDictEqual(
            child.settings, {},
            "The child apples=3 was the same as parent apples=3.")
    def test_remove_redundancies_nonmaterial_settings(self):
        """
		Tests whether non-material settings are properly removed from material
		profiles.
		"""
        material = optimise.Profile(settings={
            "material_bed_temperature": 60,
            "layer_height": 0.1337
        },
                                    filepath="/path/to/PLA.inst.cfg")
        variant = optimise.Profile(settings={
            "material_bed_temperature": 70,
            "layer_height": 0.2337
        },
                                   subprofiles=[material])
        optimise.remove_redundancies(variant)
        self.assertDictEqual(
            material.settings, {"material_bed_temperature": 60},
            "Material profiles should only contain material settings.")