Python mock.sentinel.Something() Examples

The following are 30 code examples of mock.sentinel.Something(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mock.sentinel , or try the search function .
Example #1
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement_nested(self):
        with catch_warnings(record=True):
            with patch('%s.something' % __name__) as mock_something:
                with patch('%s.something_else' % __name__) as mock_something_else:
                    self.assertEqual(something, mock_something, "unpatched")
                    self.assertEqual(something_else, mock_something_else,
                                     "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #2
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_exception(self):
        try:
            with patch('%s.something' % __name__, sentinel.Something2):
                self.assertEqual(something, sentinel.Something2, "unpatched")
                raise Exception('pow')
        except Exception:
            pass
        else:
            self.fail("patch swallowed exception")
        self.assertEqual(something, sentinel.Something) 
Example #3
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_as(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertTrue(is_instance(mock_something, MagicMock),
                            "patching wrong type")
        self.assertEqual(something, sentinel.Something) 
Example #4
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_nested(self):
        with catch_warnings(record=True):
            with patch('%s.something' % __name__) as mock_something:
                with patch('%s.something_else' % __name__) as mock_something_else:
                    self.assertEqual(something, mock_something, "unpatched")
                    self.assertEqual(something_else, mock_something_else,
                                     "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #5
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_specified(self):
        with patch('%s.something' % __name__, sentinel.Patched) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertEqual(mock_something, sentinel.Patched, "wrong patch")
        self.assertEqual(something, sentinel.Something) 
Example #6
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_imbricated(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")

            with patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #7
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement(self):
        with patch('%s.something' % __name__, sentinel.Something2):
            self.assertEqual(something, sentinel.Something2, "unpatched")
        self.assertEqual(something, sentinel.Something) 
Example #8
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement_exception(self):
        try:
            with patch('%s.something' % __name__, sentinel.Something2):
                self.assertEqual(something, sentinel.Something2, "unpatched")
                raise Exception('pow')
        except Exception:
            pass
        else:
            self.fail("patch swallowed exception")
        self.assertEqual(something, sentinel.Something) 
Example #9
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement_as(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertTrue(is_instance(mock_something, MagicMock),
                            "patching wrong type")
        self.assertEqual(something, sentinel.Something) 
Example #10
Source File: testwith.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement(self):
        with patch('%s.something' % __name__, sentinel.Something2):
            self.assertEqual(something, sentinel.Something2, "unpatched")
        self.assertEqual(something, sentinel.Something) 
Example #11
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement_specified(self):
        with patch('%s.something' % __name__, sentinel.Patched) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertEqual(mock_something, sentinel.Patched, "wrong patch")
        self.assertEqual(something, sentinel.Something) 
Example #12
Source File: testwith.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_with_statement_imbricated(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")

            with patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #13
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement(self):
        with patch('%s.something' % __name__, sentinel.Something2):
            self.assertEqual(something, sentinel.Something2, "unpatched")
        self.assertEqual(something, sentinel.Something) 
Example #14
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_exception(self):
        try:
            with patch('%s.something' % __name__, sentinel.Something2):
                self.assertEqual(something, sentinel.Something2, "unpatched")
                raise Exception('pow')
        except Exception:
            pass
        else:
            self.fail("patch swallowed exception")
        self.assertEqual(something, sentinel.Something) 
Example #15
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_as(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertTrue(is_instance(mock_something, MagicMock),
                            "patching wrong type")
        self.assertEqual(something, sentinel.Something) 
Example #16
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_nested(self):
        with catch_warnings(record=True):
            with patch('%s.something' % __name__) as mock_something:
                with patch('%s.something_else' % __name__) as mock_something_else:
                    self.assertEqual(something, mock_something, "unpatched")
                    self.assertEqual(something_else, mock_something_else,
                                     "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #17
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_specified(self):
        with patch('%s.something' % __name__, sentinel.Patched) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertEqual(mock_something, sentinel.Patched, "wrong patch")
        self.assertEqual(something, sentinel.Something) 
Example #18
Source File: testwith.py    From odoo12-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_with_statement_imbricated(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")

            with patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #19
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement_nested(self):
        with catch_warnings(record=True):
            with patch('%s.something' % __name__) as mock_something, patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something, mock_something, "unpatched")
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #20
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement_exception(self):
        try:
            with patch('%s.something' % __name__, sentinel.Something2):
                self.assertEqual(something, sentinel.Something2, "unpatched")
                raise Exception('pow')
        except Exception:
            pass
        else:
            self.fail("patch swallowed exception")
        self.assertEqual(something, sentinel.Something) 
Example #21
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement_as(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertTrue(is_instance(mock_something, MagicMock),
                            "patching wrong type")
        self.assertEqual(something, sentinel.Something) 
Example #22
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement_nested(self):
        with catch_warnings(record=True):
            with patch('%s.something' % __name__) as mock_something:
                with patch('%s.something_else' % __name__) as mock_something_else:
                    self.assertEqual(something, mock_something, "unpatched")
                    self.assertEqual(something_else, mock_something_else,
                                     "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #23
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement_specified(self):
        with patch('%s.something' % __name__, sentinel.Patched) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertEqual(mock_something, sentinel.Patched, "wrong patch")
        self.assertEqual(something, sentinel.Something) 
Example #24
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement_imbricated(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")

            with patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse) 
Example #25
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement(self):
        with patch('%s.something' % __name__, sentinel.Something2):
            self.assertEqual(something, sentinel.Something2, "unpatched")
        self.assertEqual(something, sentinel.Something) 
Example #26
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement_exception(self):
        with self.assertRaises(SampleException):
            with patch('%s.something' % __name__, sentinel.Something2):
                self.assertEqual(something, sentinel.Something2, "unpatched")
                raise SampleException()
        self.assertEqual(something, sentinel.Something) 
Example #27
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement_as(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertTrue(is_instance(mock_something, MagicMock),
                            "patching wrong type")
        self.assertEqual(something, sentinel.Something) 
Example #28
Source File: testwith.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_with_statement(self):
        with patch('%s.something' % __name__, sentinel.Something2):
            self.assertEqual(something, sentinel.Something2, "unpatched")
        self.assertEqual(something, sentinel.Something) 
Example #29
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement_specified(self):
        with patch('%s.something' % __name__, sentinel.Patched) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")
            self.assertEqual(mock_something, sentinel.Patched, "wrong patch")
        self.assertEqual(something, sentinel.Something) 
Example #30
Source File: testwith.py    From mock with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_with_statement_imbricated(self):
        with patch('%s.something' % __name__) as mock_something:
            self.assertEqual(something, mock_something, "unpatched")

            with patch('%s.something_else' % __name__) as mock_something_else:
                self.assertEqual(something_else, mock_something_else,
                                 "unpatched")

        self.assertEqual(something, sentinel.Something)
        self.assertEqual(something_else, sentinel.SomethingElse)