Example #1
0
    def test_profiles(self, machine_manager):
        profile_1 = Profile(machine_manager)
        profile_2 = Profile(machine_manager)
        definition = MachineDefinition(
            machine_manager,
            self._getDefinitionsFilePath("simple_machine.json"))
        definition.loadMetaData()
        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager,
                                           definition=definition,
                                           name="Basic Test")
        machine_instance.loadFromFile(
            self._getInstancesFilePath("simple_machine.cfg"))
        machine_manager.addMachineInstance(machine_instance)
        profile_1._active_instance = machine_instance
        profile_2._active_instance = machine_instance

        profile_1.loadFromFile(
            self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        profile_2.loadFromFile(
            self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check if adding again has no effect
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check that adding another profile with same name does not work
        with pytest.raises(DuplicateProfileError):
            machine_manager.addProfile(profile_2)

        # Changing the name and then adding it should work
        profile_2.setName("test")
        machine_manager.addProfile(profile_2)
        assert profile_1 in machine_manager.getProfiles(
        ) and profile_2 in machine_manager.getProfiles()

        assert machine_manager.findProfile("test") == profile_2

        # Check if removing one of the profiles works
        machine_manager.removeProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_2]

        machine_manager.setActiveProfile(profile_2)
        assert machine_manager.getActiveProfile() == profile_2

        machine_manager.removeProfile(profile_2)

        assert machine_manager.getProfiles() == []
Example #2
0
    def test_loadAndSave(self, machine_manager, definition_file_name, instance_file_name, profile_file_name, target_profile_file_name):
        profile = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath(definition_file_name))
        definition.loadMetaData()

        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition)
        machine_instance.loadFromFile(self._getInstancesFilePath(instance_file_name))
        profile._active_instance = machine_instance
        profile.loadFromFile(self._getProfileFilePath(profile_file_name))
        try:
            os.remove(self._getProfileFilePath(target_profile_file_name)) # Clear any previous tests
        except:
            pass
        profile.saveToFile(self._getProfileFilePath(target_profile_file_name))

        config_loaded = configparser.ConfigParser()
        config_loaded.read(self._getProfileFilePath(instance_file_name))
        config_saved = configparser.ConfigParser()
        config_saved.read(self._getProfileFilePath(target_profile_file_name))

        for section in config_loaded.sections():
            assert section in config_saved.sections()
            for key in config_loaded[section]:
                assert key in config_saved[section]
                assert config_loaded[section][key] == config_saved[section][key]
Example #3
0
    def test_profiles(self, machine_manager):
        profile_1 = Profile(machine_manager)
        profile_2 = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath("simple_machine.json"))
        definition.loadMetaData()
        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition, name = "Basic Test")
        machine_instance.loadFromFile(self._getInstancesFilePath("simple_machine.cfg"))
        machine_manager.addMachineInstance(machine_instance)
        profile_1._active_instance = machine_instance
        profile_2._active_instance = machine_instance

        profile_1.loadFromFile(self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        profile_2.loadFromFile(self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check if adding again has no effect
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check that adding another profile with same name does not work
        with pytest.raises(DuplicateProfileError):
            machine_manager.addProfile(profile_2)

        # Changing the name and then adding it should work
        profile_2.setName("test")
        machine_manager.addProfile(profile_2)
        assert profile_1 in machine_manager.getProfiles() and profile_2 in machine_manager.getProfiles()

        assert machine_manager.findProfile("test") == profile_2

        # Check if removing one of the profiles works
        machine_manager.removeProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_2]

        machine_manager.setActiveProfile(profile_2)
        assert machine_manager.getActiveProfile() == profile_2

        machine_manager.removeProfile(profile_2)
        
        assert machine_manager.getProfiles() == []
Example #4
0
    def test_profileOverride(self, machine_manager, definition_file_name, instance_file_name, profile_file_name, expected_values):
        profile = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath(definition_file_name))
        definition.loadMetaData()

        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition)
        machine_instance.loadFromFile(self._getInstancesFilePath(instance_file_name))
        profile._active_instance = machine_instance
        profile.loadFromFile(self._getProfileFilePath(profile_file_name))

        for key in expected_values:
            assert profile.getSettingValue(key) == expected_values[key]