Beispiel #1
0
def one(request):
    """returns MyInt(1)"""
    yield MyInt(1)
    print("tear down code of one fixture")
Beispiel #2
0
def zero(request):
    """returns MyInt(0)"""    
    def fin():
        print("tear down code of zero fixture")
    request.addfinalizer(fin)
    return MyInt(0)
Beispiel #3
0
 def __add__(self, other):
     return MyInt(self.v + other.v)
Beispiel #4
0
 def __sub__(self, other):
     return MyInt(self.v - other.v)
Beispiel #5
0
 def test_add(self):
     """Testing adding functionality"""
     a = MyInt(2)
     b = MyInt(3)
     self.assertEqual(a + b, MyInt(5))
Beispiel #6
0
	

def process(op, a, b):
	if op == '+': return a + b
	if op == '-': return a - b	
	if op == '==': return a == b
	if op == '!=': return a != b
	if op == '>': return a > b
	if op == '<': return a < b
	if op == '>=': return a >= b
	if op == '<=': return a <= b
	
#Note sequence in 1st arg of parametrize and test_eval args are not same 
#Note the generated ids
@pytest.mark.parametrize("a, op, b, expected", [
    ( MyInt(2), '+',  MyInt(2), MyInt(4)),
    pytest.param(MyInt(2), '-',  MyInt(2), MyInt(0), marks=pytest.mark.addl),
  ])
def test_eval(a, b, op, expected):
	assert process(op,a,b) == expected
    
    
#generated through pytest_generate_tests
def test_many(param1, op, param2, op2, result):
	assert process(op2, process(op,param1,param2),result)
    
    
    
#Test command line 
class TestMyInt:
    def test_commandline(self,commandMyInt):
Beispiel #7
0
 def test_great(self):
     """Testing great comparision functionality"""
     a = MyInt(2)
     b = MyInt(3)
     self.assertGreater(a, b)
Beispiel #8
0
 def test_less(self):
     """Testing less comparision functionality"""
     a = MyInt(2)
     b = MyInt(3)
     self.assertLess(a, b)
Beispiel #9
0
 def test_add(self):
     '''testing add functionality'''
     a = MyInt(1)
     b = MyInt(2)
     self.assertEqual(a + b , MyInt(3))
Beispiel #10
0
 def test_less(self):
     '''testing less than  functionality'''
     a = MyInt(1)
     b = MyInt(2)
     self.assertLess(a,b)
Beispiel #11
0
 def test_add(self):
     """Testing add functionality"""
     a = MyInt(2)
     b = MyInt(3)
     c = a+b
     self.assertEqual(c, MyInt(5))