Here are the examples of the python api mock.bar taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
Source : testmock.py
with GNU General Public License v3.0
from guohuadeng
with GNU General Public License v3.0
from guohuadeng
def test_repr(self):
mock = Mock(name='foo')
self.assertIn('foo', repr(mock))
self.assertIn("'%s'" % id(mock), repr(mock))
mocks = [(Mock(), 'mock'), (Mock(name='bar'), 'bar')]
for mock, name in mocks:
self.assertIn('%s.bar' % name, repr(mock.bar))
self.assertIn('%s.foo()' % name, repr(mock.foo()))
self.assertIn('%s.foo().bing' % name, repr(mock.foo().bing))
self.assertIn('%s()' % name, repr(mock()))
self.assertIn('%s()()' % name, repr(mock()()))
self.assertIn('%s()().foo.bar.baz().bing' % name,
repr(mock()().foo.bar.baz().bing))
def test_repr_with_spec(self):
3
Source : testmock.py
with GNU General Public License v3.0
from guohuadeng
with GNU General Public License v3.0
from guohuadeng
def test_spec_old_style_classes(self):
class Foo:
bar = 7
mock = Mock(spec=Foo)
mock.bar = 6
self.assertRaises(AttributeError, lambda: mock.foo)
mock = Mock(spec=Foo())
mock.bar = 6
self.assertRaises(AttributeError, lambda: mock.foo)
@unittest.skipIf(six.PY3, "no old style classes in Python 3")
0
Source : testmock.py
with GNU General Public License v3.0
from guohuadeng
with GNU General Public License v3.0
from guohuadeng
def test_spec_set_old_style_classes(self):
class Foo:
bar = 7
mock = Mock(spec_set=Foo)
mock.bar = 6
self.assertRaises(AttributeError, lambda: mock.foo)
def _set():
mock.foo = 3
self.assertRaises(AttributeError, _set)
mock = Mock(spec_set=Foo())
mock.bar = 6
self.assertRaises(AttributeError, lambda: mock.foo)
def _set():
mock.foo = 3
self.assertRaises(AttributeError, _set)
def test_subclass_with_properties(self):