Beispiel #1
0
    def test_add_group(self, mock_groups):
        mock_group = MagicMock(spec=manager.AOVGroup)

        aov_file = manager.AOVFile(None)
        aov_file.add_group(mock_group)

        mock_groups.return_value.append.assert_called_with(mock_group)
Beispiel #2
0
    def test_add_aov(self, mock_aovs):
        mock_aov = MagicMock(spec=manager.AOV)

        aov_file = manager.AOVFile(None)
        aov_file.add_aov(mock_aov)

        mock_aovs.return_value.append.assert_called_with(mock_aov)
Beispiel #3
0
    def test__create_groups_all_data(self, mock_group, mock_expand, mock_path, mock_groups):
        mock_group_name = MagicMock(spec=str)
        mock_includes = MagicMock(spec=list)
        mock_comment = MagicMock(spec=str)
        mock_priority = MagicMock(spec=int)
        mock_icon = MagicMock(spec=str)

        group_data = {
            consts.GROUP_INCLUDE_KEY: mock_includes,
            consts.COMMENT_KEY: mock_comment,
            consts.PRIORITY_KEY: mock_priority,
            consts.GROUP_ICON_KEY: mock_icon
        }

        definitions = {mock_group_name: group_data}

        groups = []
        mock_groups.return_value = groups

        aov_file = manager.AOVFile(None)

        aov_file._create_groups(definitions)

        mock_group.assert_called_with(mock_group_name)

        self.assertEqual(groups, [mock_group.return_value])

        mock_expand.assert_called_with(mock_icon)

        self.assertEqual(mock_group.return_value.path, mock_path.return_value)
        self.assertEqual(mock_group.return_value.comment, mock_comment)
        self.assertEqual(mock_group.return_value.priority, mock_priority)
        self.assertEqual(mock_group.return_value.icon, mock_expand.return_value)

        mock_group.return_value.includes.extend.assert_called_with(mock_includes)
Beispiel #4
0
    def test_write_to_file(self, mock_groups, mock_aovs, mock_path, mock_dump):
        mock_group_key = MagicMock(spec=str)
        mock_group_value = MagicMock(spec=str)

        mock_group = MagicMock(spec=manager.AOVGroup)
        mock_group.as_data.return_value = {mock_group_key: mock_group_value}

        mock_groups.return_value = [mock_group]

        mock_aov_key = MagicMock(spec=str)
        mock_aov_value = MagicMock(spec=str)

        mock_aov = MagicMock(spec=manager.AOV)
        mock_aov.as_data.return_value = {mock_aov_key: mock_aov_value}

        mock_aovs.return_value = [mock_aov]

        aov_file = manager.AOVFile(None)

        expected = {
            consts.FILE_GROUPS_KEY: {mock_group_key: mock_group_value},
            consts.FILE_DEFINITIONS_KEY: [{mock_aov_key: mock_aov_value}]
        }

        with patch("__builtin__.open", mock_open()) as mock_handle:
            aov_file.write_to_file()

            mock_handle.assert_called_with(mock_path.return_value, 'w')

            mock_dump.assert_called_with(expected, mock_handle.return_value, indent=4)
Beispiel #5
0
    def test_exists(self, mock_isfile, mock_path):
        aov_file = manager.AOVFile(None)

        self.assertEqual(aov_file.exists, mock_isfile.return_value)

        mock_isfile.assert_called_with(mock_path.return_value)

        with self.assertRaises(AttributeError):
            aov_file.exists = False
Beispiel #6
0
    def test_contains_group(self, mock_groups):
        mock_group = MagicMock(spec=manager.AOVGroup)

        aov_file = manager.AOVFile(None)
        result = aov_file.contains_group(mock_group)

        self.assertEqual(result, mock_groups.return_value.__contains__.return_value)

        mock_groups.return_value.__contains__.assert_called_with(mock_group)
Beispiel #7
0
    def test_contains_aov(self, mock_aovs):
        mock_aov = MagicMock(spec=manager.AOV)

        aov_file = manager.AOVFile(None)
        result = aov_file.contains_aov(mock_aov)

        self.assertEqual(result, mock_aovs.return_value.__contains__.return_value)

        mock_aovs.return_value.__contains__.assert_called_with(mock_aov)
Beispiel #8
0
    def test_replace_group(self, mock_groups):
        mock_group = MagicMock(spec=manager.AOVGroup)

        mock_groups.return_value.index.return_value = 2

        aov_file = manager.AOVFile(None)
        aov_file.replace_group(mock_group)

        mock_groups.return_value.index.assert_called_with(mock_group)
        mock_groups.return_value.__setitem__.assert_called_with(2, mock_group)
Beispiel #9
0
    def test_replace_aov(self, mock_aovs):
        mock_aov = MagicMock(spec=manager.AOV)

        mock_aovs.return_value.index.return_value = 3

        aov_file = manager.AOVFile(None)
        aov_file.replace_aov(mock_aov)

        mock_aovs.return_value.index.assert_called_with(mock_aov)
        mock_aovs.return_value.__setitem__.assert_called_with(3, mock_aov)
Beispiel #10
0
    def test_remove_group(self, mock_groups):
        mock_group = MagicMock(spec=manager.AOVGroup)

        groups = [mock_group]
        mock_groups.return_value = groups

        aov_file = manager.AOVFile(None)
        aov_file.remove_group(mock_group)

        self.assertEqual(groups, [])
Beispiel #11
0
    def test_remove_aov(self, mock_aovs):
        mock_aov = MagicMock(spec=manager.AOV)

        aovs = [mock_aov]
        mock_aovs.return_value = aovs

        aov_file = manager.AOVFile(None)
        aov_file.remove_aov(mock_aov)

        self.assertEqual(aovs, [])
Beispiel #12
0
    def test___init___does_not_exist(self, mock_exists, mock_init):
        mock_path = MagicMock(spec=str)

        aov_file = manager.AOVFile(mock_path)

        self.assertEqual(aov_file._path, mock_path)
        self.assertEqual(aov_file._aovs, [])
        self.assertEqual(aov_file._data, {})
        self.assertEqual(aov_file._groups, [])

        mock_init.assert_not_called()
Beispiel #13
0
    def test_aovs(self):
        mock_aov = MagicMock(spec=manager.AOV)

        aov_file = manager.AOVFile(None)

        aov_file._aovs = [mock_aov]

        self.assertEqual(aov_file.aovs, [mock_aov])

        with self.assertRaises(AttributeError):
            aov_file.aovs = []
Beispiel #14
0
    def test_path(self):
        mock_value = MagicMock(spec=str)

        aov_file = manager.AOVFile(None)

        aov_file._path = mock_value

        self.assertEqual(aov_file.path, mock_value)

        with self.assertRaises(AttributeError):
            aov_file.path = mock_value
Beispiel #15
0
    def test_groups(self):
        mock_group = MagicMock(spec=manager.AOVGroup)

        aov_file = manager.AOVFile(None)

        aov_file._groups = [mock_group]

        self.assertEqual(aov_file.groups, [mock_group])

        with self.assertRaises(AttributeError):
            aov_file.groups = []
Beispiel #16
0
    def test__init_from_file__no_items(self, mock_path, mock_load, mock_create_aovs, mock_create_groups):
        aov_file = manager.AOVFile(None)

        with patch("__builtin__.open", mock_open()) as mock_handle:
            aov_file._init_from_file()

            mock_handle.assert_called_with(mock_path.return_value)

            mock_load.assert_called_with(mock_handle.return_value)

        mock_create_aovs.assert_not_called()
        mock_create_groups.assert_not_called()
Beispiel #17
0
    def test_write_to_file__nothing_explicit_path(self, mock_groups, mock_aovs, mock_dump):
        mock_groups.return_value = []
        mock_aovs.return_value = []

        aov_file = manager.AOVFile(None)

        mock_path = MagicMock(spec=str)

        with patch("__builtin__.open", mock_open()) as mock_handle:
            aov_file.write_to_file(mock_path)

            mock_handle.assert_called_with(mock_path, 'w')

            mock_dump.assert_called_with({}, mock_handle.return_value, indent=4)
Beispiel #18
0
    def accept(self):
        """Accept the operation."""
        aov_data = self.buildAOVDataFromUI()

        self.aov._updateData(aov_data)

        # Open file for writing.
        aov_file = manager.AOVFile(self.aov.path)
        aov_file.replaceAOV(self.aov)
        aov_file.writeToFile()

        self.aovUpdatedSignal.emit(self.aov)

        return super(EditAOVDialog, self).accept()
Beispiel #19
0
    def accept(self):
        """Accept the operation."""
        aov_data = self.build_aov_data_from_ui()

        self.aov.update_data(aov_data)

        # Open file for writing.
        aov_file = manager.AOVFile(self.aov.path)
        aov_file.replace_aov(self.aov)
        aov_file.write_to_file()

        self.aov_updated_signal.emit(self.aov)

        return super(EditAOVDialog, self).accept()
Beispiel #20
0
    def accept(self):
        """Accept the operation."""
        # Want to edit the existing group so use it and clear out the
        # current AOVs.
        group = self._group
        group.clear()

        self.buildGroupFromUI(group)

        aov_file = manager.AOVFile(group.path)
        aov_file.replaceGroup(group)
        aov_file.writeToFile()

        self.groupUpdatedSignal.emit(group)

        return super(EditGroupDialog, self).accept()
Beispiel #21
0
    def accept(self):
        """Accept the operation."""
        aov_data = {}

        aov_data["variable"] = self.variable_name.text()
        aov_data["vextype"] = self.type_box.itemData(self.type_box.currentIndex())

        self.buildAOVDataFromUI(aov_data)

        aov = AOV(aov_data)

        # Open file for writing.
        aov_file = manager.AOVFile(aov.path)

#        if aov_file.exists:
#                if aov_file.containsAOV(new_aov):

#                    existing_aov = aov_file.aovs[aov_file.aovs.index(new_aov)]

#                    choice = hou.ui.displayMessage(
#                        "{} already exists in file, overwrite?".format(new_aov.variable),
#                        buttons=("Cancel", "OK"),
#                        severity=hou.severityType.Warning,
#                        details=str(existing_aov.getData()),
#                        details_expanded=True,
#                    )
#
#                    if choice == 0:
#                        return

#                    aov_file.replaceAOV(new_aov)

#                else:
#                    aov_file.addAOV(new_aov)

#            else:
#                aov_file.addAOV(new_aov)

        aov_file.addAOV(aov)

        aov_file.writeToFile()

        self.newAOVSignal.emit(aov)

        return super(NewAOVDialog, self).accept()
Beispiel #22
0
    def test___init___does_not_exist(self, mocker):
        mocker.patch.object(
            manager.AOVFile,
            "exists",
            new_callable=mocker.PropertyMock(return_value=False),
        )
        mock_init = mocker.patch.object(manager.AOVFile, "_init_from_file")

        mock_path = mocker.MagicMock(spec=str)

        aov_file = manager.AOVFile(mock_path)

        assert aov_file._path == mock_path
        assert aov_file._aovs == []
        assert aov_file._data == {}
        assert aov_file._groups == []

        mock_init.assert_not_called()
Beispiel #23
0
    def delete(self):
        """Delete the currently selected AOV."""
        self.accept()

        choice = hou.ui.displayMessage(
            "Are you sure you want to delete {}?".format(self.group.name),
            buttons=("Cancel", "OK"),
            severity=hou.severityType.Warning,
            close_choice=0,
            help="This action cannot be undone.",
            title="Confirm Group Deletion")

        if choice == 1:
            aov_file = manager.AOVFile(self.group.path)
            aov_file.removeGroup(self.group)
            aov_file.writeToFile()

            manager.MANAGER.removeGroup(self.group)
Beispiel #24
0
    def accept(self):
        """Accept the operation."""
        group_name = str(self.group_name.text())

        group = AOVGroup(group_name)
        group.path = os.path.expandvars(self.file_widget.getPath())

        self.buildGroupFromUI(group)

        aov_file = manager.AOVFile(group.path)

        aov_file.addGroup(group)

        aov_file.writeToFile()

        self.newAOVGroupSignal.emit(group)

        return super(NewGroupDialog, self).accept()
Beispiel #25
0
    def test__create_groups_minimal(self, mock_group, mock_path, mock_groups):
        mock_group_name = MagicMock(spec=str)

        group_data = {}

        definitions = {mock_group_name: group_data}

        groups = []
        mock_groups.return_value = groups

        aov_file = manager.AOVFile(None)

        aov_file._create_groups(definitions)

        mock_group.assert_called_with(mock_group_name)

        self.assertEqual(groups, [mock_group.return_value])

        self.assertEqual(mock_group.return_value.path, mock_path.return_value)
Beispiel #26
0
    def test__init_from_file__items(self, mock_path, mock_load, mock_create_aovs, mock_create_groups):
        mock_definitions = MagicMock(spec=dict)
        mock_groups = MagicMock(spec=dict)

        mock_load.return_value = {
            consts.FILE_DEFINITIONS_KEY: mock_definitions,
            consts.FILE_GROUPS_KEY: mock_groups,
        }

        aov_file = manager.AOVFile(None)

        with patch("__builtin__.open", mock_open()) as mock_handle:
            aov_file._init_from_file()

            mock_handle.assert_called_with(mock_path.return_value)

            mock_load.assert_called_with(mock_handle.return_value)

        mock_create_aovs.assert_called_with(mock_definitions)
        mock_create_groups.assert_called_with(mock_groups)
Beispiel #27
0
    def test__create_aovs(self, mock_path, mock_aov, mock_aovs):
        definition = {
            "key": "value"
        }

        definitions = [
            definition
        ]

        aovs = []
        mock_aovs.return_value = aovs

        aov_file = manager.AOVFile(None)

        aov_file._create_aovs(definitions)

        mock_aov.assert_called_with({"key": "value", "path": mock_path.return_value})

        self.assertEqual(definition, {"key": "value", "path": mock_path.return_value})

        self.assertEqual(aovs, [mock_aov.return_value])
Beispiel #28
0
    def test___init__(self, mocker, exists):
        """Test object initialization."""
        mocker.patch.object(
            manager.AOVFile,
            "exists",
            new_callable=mocker.PropertyMock(return_value=exists),
        )
        mock_init = mocker.patch.object(manager.AOVFile, "_init_from_file")

        mock_path = mocker.MagicMock(spec=str)

        aov_file = manager.AOVFile(mock_path)

        assert aov_file._path == mock_path
        assert aov_file._aovs == []
        assert aov_file._data == {}
        assert aov_file._groups == []

        if exists:
            mock_init.assert_called()

        else:
            mock_init.assert_not_called()
Beispiel #29
0
 def _create():
     return manager.AOVFile(None)