當前位置: 首頁>>代碼示例>>Python>>正文


Python mock.DEFAULT屬性代碼示例

本文整理匯總了Python中mock.DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Python mock.DEFAULT屬性的具體用法?Python mock.DEFAULT怎麽用?Python mock.DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在mock的用法示例。


在下文中一共展示了mock.DEFAULT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _patch_object

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def _patch_object(
    target,
    attribute,
    new=mock.DEFAULT,
    spec=None,
    create=False,
    mocksignature=False,
    spec_set=None,
    autospec=False,
    new_callable=None,
    **kwargs
):
    getter = lambda: target
    return _make_patch_async(
        getter,
        attribute,
        new,
        spec,
        create,
        mocksignature,
        spec_set,
        autospec,
        new_callable,
        kwargs,
    ) 
開發者ID:quora,項目名稱:asynq,代碼行數:27,代碼來源:mock_.py

示例2: test_processExtendedGcode_excluding_noMatch

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_processExtendedGcode_excluding_noMatch(self):
        """Test processExtendedGcode when excluding and no entry matches."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
            unit,
            extendedExcludeGcodes=mock.DEFAULT,
            _processExtendedGcodeEntry=mock.DEFAULT
        ) as mocks:
            unit.excluding = True
            mocks["extendedExcludeGcodes"].get.return_value = None

            result = unit.processExtendedGcode("G1 X1 Y2", "G1", None)

            mocks["extendedExcludeGcodes"].get.assert_called_with("G1")
            mocks["_processExtendedGcodeEntry"].assert_not_called()
            self.assertIsNone(result, "The return value should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:20,代碼來源:test_ExcludeRegionState_processExtendedGcode.py

示例3: test_processExtendedGcode_excluding_matchExists

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_processExtendedGcode_excluding_matchExists(self):
        """Test processExtendedGcode when excluding and a matching entry exists."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
            unit,
            extendedExcludeGcodes=mock.DEFAULT,
            _processExtendedGcodeEntry=mock.DEFAULT
        ) as mocks:
            unit.excluding = True
            mockEntry = mock.Mock(name="entry")
            mockEntry.mode = "expectedMode"
            mocks["extendedExcludeGcodes"].get.return_value = mockEntry
            mocks["_processExtendedGcodeEntry"].return_value = "expectedResult"

            result = unit.processExtendedGcode("G1 X1 Y2", "G1", None)

            mocks["extendedExcludeGcodes"].get.assert_called_with("G1")
            mocks["_processExtendedGcodeEntry"].assert_called_with("expectedMode", "G1 X1 Y2", "G1")
            self.assertEqual(
                result, "expectedResult",
                "The expected result of _processExtendedGcodeEntry should be returned"
            ) 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:26,代碼來源:test_ExcludeRegionState_processExtendedGcode.py

示例4: test_processExtendedGcode_notExcluding_matchExists

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_processExtendedGcode_notExcluding_matchExists(self):
        """Test processExtendedGcode when not excluding and a matching entry exists."""
        mockLogger = mock.Mock()
        mockLogger.isEnabledFor.return_value = False  # For coverage of logging condition
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
            unit,
            extendedExcludeGcodes=mock.DEFAULT,
            _processExtendedGcodeEntry=mock.DEFAULT
        ) as mocks:
            unit.excluding = False
            mockEntry = mock.Mock(name="entry")
            mockEntry.mode = "expectedMode"
            mocks["extendedExcludeGcodes"].get.return_value = mockEntry

            result = unit.processExtendedGcode(AnyIn(["G1 X1 Y2", "G1 Y2 X1"]), "G1", None)

            mocks["extendedExcludeGcodes"].get.assert_not_called()
            mocks["_processExtendedGcodeEntry"].assert_not_called()
            self.assertIsNone(result, "The return value should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:23,代碼來源:test_ExcludeRegionState_processExtendedGcode.py

示例5: _test_on_event_stopPrinting

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def _test_on_event_stopPrinting(self, eventType, clearRegions):
        """Test the on_event method when an event is received that indicates printing stopped."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            simulate_isActivePrintJob(unit, True)
            unit.clearRegionsAfterPrintFinishes = clearRegions

            mockPayload = mock.Mock()

            result = unit.on_event(eventType, mockPayload)

            self.assertFalse(unit.isActivePrintJob, "isActivePrintJob should report False")
            self.assertIsNone(result, "The result should be None")

            if (clearRegions):
                mocks['state'].resetState.assert_called_with(True)
                mocks['_notifyExcludedRegionsChanged'].assert_called_with()
            else:
                mocks['state'].resetState.assert_not_called()
                mocks['_notifyExcludedRegionsChanged'].assert_not_called() 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:26,代碼來源:test_ExcludeRegionPlugin.py

示例6: test_handleAddExcludeRegion_success

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleAddExcludeRegion_success(self):
        """Test _handleAddExcludeRegion when state.addRegion succeeds."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            mockRegion = mock.Mock()

            result = unit._handleAddExcludeRegion(mockRegion)  # pylint: disable=protected-access

            mocks["state"].addRegion.assert_called_with(mockRegion)
            mocks["_notifyExcludedRegionsChanged"].assert_called()

            self.assertIsNone(result, "The result should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:18,代碼來源:test_ExcludeRegionPlugin.py

示例7: test_handleAddExcludeRegion_ValueError

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleAddExcludeRegion_ValueError(self):
        """Test _handleAddExcludeRegion when state.addRegion raises a ValueError."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            mocks["state"].addRegion.side_effect = ValueError("ExpectedError")

            mockRegion = mock.Mock()

            result = unit._handleAddExcludeRegion(mockRegion)  # pylint: disable=protected-access

            mocks["state"].addRegion.assert_called_with(mockRegion)
            mocks["_notifyExcludedRegionsChanged"].assert_not_called()

            self.assertEqual(
                result, ("ExpectedError", 409),
                "A 409 error response tuple should be returned"
            ) 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:23,代碼來源:test_ExcludeRegionPlugin.py

示例8: test_handleDeleteExcludeRegion_success_deleted

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleDeleteExcludeRegion_success_deleted(self):
        """Test _handleDeleteExcludeRegion when state.deleteRegion returns True."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            mocks["state"].deleteRegion.return_value = True

            result = unit._handleDeleteExcludeRegion("someId")  # pylint: disable=protected-access

            mocks["state"].deleteRegion.assert_called_with("someId")
            mocks["_notifyExcludedRegionsChanged"].assert_called()

            self.assertIsNone(result, "The result should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:18,代碼來源:test_ExcludeRegionPlugin.py

示例9: test_handleDeleteExcludeRegion_success_not_found

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleDeleteExcludeRegion_success_not_found(self):
        """Test _handleDeleteExcludeRegion when state.deleteRegion returns False."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            mocks["state"].deleteRegion.return_value = False

            result = unit._handleDeleteExcludeRegion("someId")  # pylint: disable=protected-access

            mocks["state"].deleteRegion.assert_called_with("someId")
            mocks["_notifyExcludedRegionsChanged"].assert_not_called()

            self.assertIsNone(result, "The result should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:18,代碼來源:test_ExcludeRegionPlugin.py

示例10: test_handleDeleteExcludeRegion_no_del_while_printing

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleDeleteExcludeRegion_no_del_while_printing(self):
        """Test _handleDeleteExcludeRegion when modification is NOT allowed while printing."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            unit.mayShrinkRegionsWhilePrinting = False
            simulate_isActivePrintJob(unit, True)
            mocks["_notifyExcludedRegionsChanged"] = mock.Mock()

            result = unit._handleDeleteExcludeRegion("someId")  # pylint: disable=protected-access

            mocks["state"].deleteRegion.assert_not_called()
            mocks["_notifyExcludedRegionsChanged"].assert_not_called()

            self.assertEqual(
                result,
                (AnyString(), 409),
                "The result should be a Tuple indicating a 409 error"
            ) 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:24,代碼來源:test_ExcludeRegionPlugin.py

示例11: test_handleUpdateExcludeRegion_success

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleUpdateExcludeRegion_success(self):
        """Test _handleUpdateExcludeRegion when state.replaceRegion succeeds."""
        unit = create_plugin_instance()
        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            unit.mayShrinkRegionsWhilePrinting = False
            simulate_isActivePrintJob(unit, False)

            mockRegion = mock.Mock()

            result = unit._handleUpdateExcludeRegion(mockRegion)  # pylint: disable=protected-access

            mocks["state"].replaceRegion.assert_called_with(mockRegion, False)
            mocks["_notifyExcludedRegionsChanged"].assert_called()

            self.assertIsNone(result, "The result should be None") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:21,代碼來源:test_ExcludeRegionPlugin.py

示例12: test_handleUpdateExcludeRegion_ValueError

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handleUpdateExcludeRegion_ValueError(self):
        """Test _handleUpdateExcludeRegion when a ValueError is raised."""
        unit = create_plugin_instance()

        with mock.patch.multiple(
            unit,
            state=mock.DEFAULT,
            _notifyExcludedRegionsChanged=mock.DEFAULT
        ) as mocks:
            unit.mayShrinkRegionsWhilePrinting = False
            simulate_isActivePrintJob(unit, True)
            mocks["state"].replaceRegion.side_effect = ValueError("ExpectedError")

            mockRegion = mock.Mock()

            result = unit._handleUpdateExcludeRegion(mockRegion)  # pylint: disable=protected-access

            mocks["state"].replaceRegion.assert_called_with(mockRegion, True)
            mocks["_notifyExcludedRegionsChanged"].assert_not_called()

            self.assertEqual(
                result, ("ExpectedError", 409),
                "A 409 error response tuple should be returned"
            ) 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:26,代碼來源:test_ExcludeRegionPlugin.py

示例13: test_handle_G2_radiusTrumpsOffsets

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handle_G2_radiusTrumpsOffsets(self):
        """Test the _handle_G2 method to ensure offsets (I, J) are ignored if a radius is given."""
        unit = self._createInstance()

        with mock.patch.multiple(
            unit,
            computeArcCenterOffsets=mock.DEFAULT,
            planArc=mock.DEFAULT
        ) as mocks:
            expectedResult = ["Command1"]
            unit.state.processLinearMoves.return_value = expectedResult
            mocks["computeArcCenterOffsets"].return_value = (12, 13)
            mocks["planArc"].return_value = [0, 1, 2, 3]

            result = unit._handle_G2(  # pylint: disable=protected-access
                "G2 R20 I8 J9 X10 Y0",
                "G2",
                None
            )

            mocks["computeArcCenterOffsets"].assert_called_with(10, 0, 20, True)
            mocks["planArc"].assert_called_with(10, 0, 12, 13, True)

            self.assertEqual(result, expectedResult, "A list of one command should be returned") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:26,代碼來源:test_GcodeHandlers.py

示例14: test_handle_G2_offsetMode_paramParsing

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_handle_G2_offsetMode_paramParsing(self):
        """Test _handle_G2 parameter parsing when center point offsets are provided."""
        unit = self._createInstance()

        unit.state.position.X_AXIS.nativeToLogical.return_value = 0
        unit.state.position.X_AXIS.nativeToLogical.return_value = 1

        expectedResult = ["Command1", "Command2"]
        unit.state.processLinearMoves.return_value = expectedResult

        with mock.patch.multiple(
            unit,
            computeArcCenterOffsets=mock.DEFAULT,
            planArc=mock.DEFAULT
        ) as mocks:
            mocks["planArc"].return_value = [4, 5]

            cmd = "G2 I6.1 J6.2 X7 Y8 Z9 E10 F11"
            result = unit._handle_G2(cmd, "G2", None)  # pylint: disable=protected-access

            mocks["computeArcCenterOffsets"].assert_not_called()
            mocks["planArc"].assert_called_with(7, 8, 6.1, 6.2, True)
            unit.state.processLinearMoves.assert_called_with(cmd, 10, 11, 9, 4, 5)

            self.assertEqual(result, expectedResult, "A list of two commands should be returned") 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:27,代碼來源:test_GcodeHandlers.py

示例15: test_processNonMove_deltaE_zero_notExcluding

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import DEFAULT [as 別名]
def test_processNonMove_deltaE_zero_notExcluding(self):
        """Test _processNonMove when deltaE is 0 and not excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
            unit,
            recordRetraction=mock.DEFAULT,
            recoverRetractionIfNeeded=mock.DEFAULT
        ) as mocks:
            unit.excluding = False
            unit.feedRate = 100

            result = unit._processNonMove("G0 E0 F100", 0)  # pylint: disable=protected-access

            mocks["recordRetraction"].assert_not_called()
            mocks["recoverRetractionIfNeeded"].assert_not_called()
            self.assertEqual(
                result, ["G0 E0 F100"],
                "The result should be a list containing the command"
            ) 
開發者ID:bradcfisher,項目名稱:OctoPrint-ExcludeRegionPlugin,代碼行數:23,代碼來源:test_ExcludeRegionState.py


注:本文中的mock.DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。