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)
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)
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)
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)
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)
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)
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)
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")
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)
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)
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())
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")
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()
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))
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
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)
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()
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)
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)
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) )
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()
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()
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()
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)