Created
October 29, 2016 12:23
-
-
Save pikhovkin/67fe180465d0edfc2ea8ea3a241740f2 to your computer and use it in GitHub Desktop.
Test for the Ramax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
__all__ = ( | |
'MyError', | |
'Parent', | |
'First', | |
'Second', | |
'A', | |
) | |
class MyError(Exception): | |
pass | |
class Parent(object): | |
def __init__(self): | |
self.i = 3 | |
def isFirst(self): | |
raise NotImplementedError | |
@property | |
def isSecond(self): | |
raise NotImplementedError | |
def fnc(self, n): | |
return n * self.i | |
class First(Parent): | |
def isFirst(self): | |
return 1 | |
@property | |
def isSecond(self): | |
return 0 | |
def fnc(self, n): | |
return super(First, self).fnc(n) * n | |
class Second(Parent): | |
def __init__(self, i): | |
super(Second, self).__init__() | |
self.i = i | |
def isFirst(self): | |
return 0 | |
@property | |
def isSecond(self): | |
return 1 | |
def fnc(self, n, m): | |
return super(Second, self).fnc(n) * m | |
class A(First): | |
def fnc(self, n): | |
if n == 7: | |
raise MyError('Error text') | |
return super(A, self).fnc(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from ma import Second | |
__all__ = ( | |
'B', | |
) | |
class B(Second): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Test Module.""" | |
from ma import * | |
from mb import B | |
def test(): | |
a = A() | |
b = B(5) | |
assert(a.i == 3) | |
assert(a.fnc(2) == 2 * 2 * 3) | |
assert(b.fnc(10, 4) == 10 * 4 * 5) | |
assert(a.isFirst() == 1) | |
assert(a.isSecond == 0) | |
assert(b.isFirst() == 0) | |
assert(b.isSecond == 1) | |
assert(isinstance(a, First)) | |
assert(isinstance(b, Second)) | |
assert(isinstance(a, Parent)) | |
assert(isinstance(b, Parent)) | |
try: | |
a.fnc(7) | |
except MyError, v: | |
if str(v) != "Error text": | |
assert(0) | |
else: | |
assert(0) | |
try: | |
a.isSecond = 2 | |
except AttributeError: | |
pass | |
else: | |
assert(0) | |
if __name__ == "__main__": | |
test() | |
print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment