예제 #1
0
    def test_found_script_does_not_exists(self, mocker, patch_hou):
        mock_exists = mocker.patch("os.path.exists", return_value=False)

        with pytest.raises(OSError):
            utils.build_pyfilter_command()

        mock_exists.assert_called_with(patch_hou["hou"].findFile.return_value)
예제 #2
0
    def test_found_script_does_not_exists(self, mocker):
        mock_find = mocker.patch("hou.findFile")
        mock_isfile = mocker.patch("os.path.isfile", return_value=False)

        with pytest.raises(OSError):
            utils.build_pyfilter_command()

        mock_isfile.assert_called_with(mock_find.return_value)
예제 #3
0
    def test_found_script_does_not_exists(self, mock_exists):
        mock_exists.return_value = False
        mock_hou = MagicMock()

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            with self.assertRaises(OSError):
                utils.build_pyfilter_command()

        mock_exists.assert_called_with(mock_hou.findFile.return_value)
예제 #4
0
    def test_found_script_does_not_exists(self, mock_exists):
        mock_exists.return_value = False
        mock_hou = MagicMock()

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            with self.assertRaises(OSError):
                utils.build_pyfilter_command()

        mock_exists.assert_called_with(mock_hou.findFile.return_value)
예제 #5
0
    def test_manual_path_not_found(self, mocker):
        """Test when the manual path does not exist."""
        mock_find = mocker.patch("hou.findFile")
        mock_isfile = mocker.patch("os.path.isfile", return_value=False)

        mock_path = mocker.MagicMock()

        with pytest.raises(OSError):
            utils.build_pyfilter_command(pyfilter_path=mock_path)

        mock_find.assert_not_called()
        mock_isfile.assert_called_with(mock_path)
예제 #6
0
    def test_found_script_no_args(self, mocker, patch_hou):
        mock_exists = mocker.patch("os.path.exists", return_value=True)

        result = utils.build_pyfilter_command()

        assert result == '-P "{} "'.format(patch_hou.hou.findFile.return_value)

        mock_exists.assert_called_with(patch_hou.hou.findFile.return_value)
예제 #7
0
    def test_found_script_no_args(self, mocker):
        mock_find = mocker.patch("hou.findFile")
        mock_isfile = mocker.patch("os.path.isfile", return_value=True)

        result = utils.build_pyfilter_command()

        assert result == '-P "{} "'.format(mock_find.return_value)

        mock_isfile.assert_called_with(mock_find.return_value)
예제 #8
0
    def test_found_script(self, mocker):
        """Test when a script is found."""
        mock_path = mocker.MagicMock()

        mock_find = mocker.patch("hou.findFile", return_value=mock_path)

        result = utils.build_pyfilter_command()

        assert result == '-P "{} "'.format(mock_path)

        mock_find.assert_called_with("pyfilter/ht-pyfilter.py")
예제 #9
0
    def test_manual_path(self, mocker, patch_hou):
        mock_exists = mocker.patch("os.path.exists", return_value=True)

        mock_path = mocker.MagicMock()

        result = utils.build_pyfilter_command(pyfilter_path=mock_path)

        assert result == '-P "{} "'.format(mock_path)

        patch_hou["hou"].findFile.assert_not_called()
        mock_exists.assert_called_with(mock_path)
예제 #10
0
    def test_manual_path(self, mocker):
        mock_find = mocker.patch("hou.findFile")
        mock_isfile = mocker.patch("os.path.isfile", return_value=True)

        mock_path = mocker.MagicMock()

        result = utils.build_pyfilter_command(pyfilter_path=mock_path)

        assert result == '-P "{} "'.format(mock_path)

        mock_find.return_value.assert_not_called()
        mock_isfile.assert_called_with(mock_path)
예제 #11
0
def build_pyfilter_command_from_node(node):
    """Construct the mantra command with PyFilter.

    :param node: The node to build a command from.
    :type node: hou.RopNode
    :return: The filter command.
    :rtype: str

    """
    args = build_arg_string_from_node(node)

    return build_pyfilter_command(args.split())
예제 #12
0
    def test_args(self, mocker):
        """Test passing args."""
        mock_path = mocker.MagicMock()

        mock_find = mocker.patch("hou.findFile", return_value=mock_path)

        args = ["-arg1=1", "-arg2"]

        result = utils.build_pyfilter_command(pyfilter_args=args)

        assert result == '-P "{} {}"'.format(mock_path, " ".join(args))

        mock_find.assert_called_with("pyfilter/ht-pyfilter.py")
예제 #13
0
    def test_no_found_script(self, mocker, patch_hou, mock_hou_exceptions):
        mock_logger = mocker.patch("ht.pyfilter.utils._logger")
        mock_exists = mocker.patch("os.path.exists")

        patch_hou.hou.findFile.side_effect = mock_hou_exceptions.OperationFailed

        result = utils.build_pyfilter_command()

        assert result == ""

        mock_logger.error.assert_called()

        mock_exists.assert_not_called()
예제 #14
0
    def test_found_script_no_args(self, mock_exists):
        mock_exists.return_value = True

        path = "/path/to/pyfilter.py"

        mock_hou = MagicMock()
        mock_hou.findFile.return_value = path

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command()

        self.assertEqual(result, '-P "{} "'.format(path))
예제 #15
0
def build_pyfilter_command_from_node(node):
    """Construct the mantra command with PyFilter.

    :param node: The node to build a command from.
    :type node: hou.RopNode
    :return: The filter command.
    :rtype: str

    """
    args = build_arg_string_from_node(node)

    cmd = build_pyfilter_command(args.split())

    return cmd
예제 #16
0
    def test_manual_path_args(self, mocker, patch_hou):
        mock_exists = mocker.patch("os.path.exists", return_value=True)

        mock_path = mocker.MagicMock()

        args = ["-arg1=1", "-arg2"]

        result = utils.build_pyfilter_command(pyfilter_args=args,
                                              pyfilter_path=mock_path)

        assert result == '-P "{} {}"'.format(mock_path, " ".join(args))

        patch_hou["hou"].findFile.assert_not_called()
        mock_exists.assert_called_with(mock_path)
예제 #17
0
    def test_no_found_script(self, mocker, fix_hou_exceptions):
        mock_find = mocker.patch("hou.findFile", side_effect=hou.OperationFailed)
        mock_logger = mocker.patch("ht.pyfilter.utils._logger")
        mock_isfile = mocker.patch("os.path.isfile")

        result = utils.build_pyfilter_command()

        assert result == ""

        mock_find.assert_called_with("pyfilter/ht-pyfilter.py")

        mock_logger.error.assert_called()

        mock_isfile.assert_not_called()
예제 #18
0
    def test_manual_path(self, mock_exists):
        mock_exists.return_value = True

        path = "/path/to/pyfilter.py"

        mock_hou = MagicMock()

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command(pyfilter_path=path)

        self.assertEqual(result, '-P "{} "'.format(path))

        mock_hou.findFile.assert_not_called()
        mock_exists.assert_called_with(path)
예제 #19
0
    def test_manual_path_args(self, mocker):
        mock_find = mocker.patch("hou.findFile")
        mock_isfile = mocker.patch("os.path.isfile", return_value=True)

        mock_path = mocker.MagicMock()

        args = ["-arg1=1", "-arg2"]

        result = utils.build_pyfilter_command(
            pyfilter_args=args, pyfilter_path=mock_path
        )

        assert result == '-P "{} {}"'.format(mock_path, " ".join(args))

        mock_find.return_value.assert_not_called()
        mock_isfile.assert_called_with(mock_path)
예제 #20
0
    def test_found_script_no_args(self, mock_exists):
        mock_exists.return_value = True

        path = "/path/to/pyfilter.py"

        mock_hou = MagicMock()
        mock_hou.findFile.return_value = path

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command()

        self.assertEqual(
            result,
            '-P "{} "'.format(path)
        )
예제 #21
0
    def test_no_found_script(self, mock_logger, mock_exists):
        def raise_error(*args, **kwargs):
            raise hou.OperationFailed()

        mock_hou = MagicMock()
        mock_hou.findFile.side_effect = raise_error
        mock_hou.OperationFailed = hou.OperationFailed

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command()

        self.assertEqual(result, "")

        mock_logger.error.assert_called()

        mock_exists.assert_not_called()
예제 #22
0
    def test_no_found_script(self, mock_logger, mock_exists):
        def raise_error(*args, **kwargs):
            raise hou.OperationFailed()

        mock_hou = MagicMock()
        mock_hou.findFile.side_effect = raise_error
        mock_hou.OperationFailed = hou.OperationFailed

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command()

        self.assertEqual(result, "")

        mock_logger.error.assert_called()

        mock_exists.assert_not_called()
예제 #23
0
    def test_no_found_script(self, mocker, patch_hou, mock_hou_exceptions):
        mock_logger = mocker.patch("ht.pyfilter.utils._logger")
        mock_exists = mocker.patch("os.path.exists")

        # Because we are tucking the hou import in the function we need to patch in the
        # original hou.OperationFailed so that the test will execute correctly.
        # patch_hou["hou"].OperationFailed = patch_hou["original_hou"].OperationFailed

        patch_hou[
            "hou"].findFile.side_effect = mock_hou_exceptions.OperationFailed

        result = utils.build_pyfilter_command()

        assert result == ""

        mock_logger.error.assert_called()

        mock_exists.assert_not_called()
예제 #24
0
    def test_manual_path(self, mock_exists):
        mock_exists.return_value = True

        path = "/path/to/pyfilter.py"

        mock_hou = MagicMock()

        modules = {"hou": mock_hou}

        with patch.dict("sys.modules", modules):
            result = utils.build_pyfilter_command(pyfilter_path=path)

        self.assertEqual(
            result,
            '-P "{} "'.format(path)
        )

        mock_hou.findFile.assert_not_called()
        mock_exists.assert_called_with(path)