Debian Codegraph @

tests/issues/test_issue_19.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 """
4 Test fix of bug described in GitHub Issue #19.
5 """
6
7 from sure import expect, AssertionBuilder
8 from sure.magic import is_cpython
9
10
11 def test_issue_19():
12 "Allow monkey-patching of methods already implemented by sure."
13
14 class Foo(object):
15 pass
16
17 @property
18 def should(self):
19 return 42
20
21 instance = Foo()
22 instance.do = "anything"
23 instance.doesnt = "foo"
24
25 expect(instance.do).should.be.equal("anything")
26 expect(instance.doesnt).should.be.equal("foo")
27
28 if is_cpython:
29 instance2 = Foo()
30 instance2.do.shouldnt.be.equal("anything")
31 instance.does.__class__.should.be.equal(AssertionBuilder)
32
33 # remove attribute
34 del instance.do
35
36 if is_cpython:
37 instance.do.shouldnt.be.equal("anything")
38 else:
39 expect(instance).shouldnt.have.property("do")
40
41 if is_cpython:
42 Foo.shouldnt.__class__.should.be.equal(AssertionBuilder)
43
44 Foo.shouldnt = "bar"
45 expect(Foo.shouldnt).should.be.equal("bar")
46 del Foo.shouldnt
47
48 if is_cpython:
49 Foo.shouldnt.__class__.should.be.equal(AssertionBuilder)
50 else:
51 expect(Foo).shouldnt.have.property("shouldnt")
52
53
54 expect(instance.should).should.be.equal(42)