diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/python/mock-1.0.0/docs/sentinel.txt | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/mock-1.0.0/docs/sentinel.txt')
-rw-r--r-- | third_party/python/mock-1.0.0/docs/sentinel.txt | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/third_party/python/mock-1.0.0/docs/sentinel.txt b/third_party/python/mock-1.0.0/docs/sentinel.txt new file mode 100644 index 0000000000..1c5223da0e --- /dev/null +++ b/third_party/python/mock-1.0.0/docs/sentinel.txt @@ -0,0 +1,58 @@ +========== + Sentinel +========== + + +.. currentmodule:: mock + +.. testsetup:: + + class ProductionClass(object): + def something(self): + return self.method() + + class Test(unittest2.TestCase): + def testSomething(self): + pass + self = Test('testSomething') + + +.. data:: sentinel + + The ``sentinel`` object provides a convenient way of providing unique + objects for your tests. + + Attributes are created on demand when you access them by name. Accessing + the same attribute will always return the same object. The objects + returned have a sensible repr so that test failure messages are readable. + + +.. data:: DEFAULT + + The `DEFAULT` object is a pre-created sentinel (actually + `sentinel.DEFAULT`). It can be used by :attr:`~Mock.side_effect` + functions to indicate that the normal return value should be used. + + +Sentinel Example +================ + +Sometimes when testing you need to test that a specific object is passed as an +argument to another method, or returned. It can be common to create named +sentinel objects to test this. `sentinel` provides a convenient way of +creating and testing the identity of objects like this. + +In this example we monkey patch `method` to return +`sentinel.some_object`: + +.. doctest:: + + >>> real = ProductionClass() + >>> real.method = Mock(name="method") + >>> real.method.return_value = sentinel.some_object + >>> result = real.method() + >>> assert result is sentinel.some_object + >>> sentinel.some_object + sentinel.some_object + + |