本文整理汇总了Python中service.Service.complicated_function方法的典型用法代码示例。如果您正苦于以下问题:Python Service.complicated_function方法的具体用法?Python Service.complicated_function怎么用?Python Service.complicated_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.Service
的用法示例。
在下文中一共展示了Service.complicated_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServiceTest
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
class ServiceTest(TestCase):
def setUp(self):
self.service = Service()
def bad_random_mock(self):
return 10
@patch.object(Service, 'bad_random', bad_random_mock)
def test_divide(self):
assert self.service.divide(2) == 5
assert self.service.divide(-1) == -10
def test_abs_plus(self):
assert self.service.abs_plus(-9) == 10
assert self.service.abs_plus(0) == 1
assert self.service.abs_plus(1) == 2
@patch.object(Service, 'bad_random', bad_random_mock)
def test_complicated_function(self):
res1, res2 = self.service.complicated_function(10)
assert res1 == 1
assert res2 == 0
res1, res2 = self.service.complicated_function(-1)
assert res1 == -10
assert res2 == 0
示例2: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self, mock_service):
# values for divide
y = [-7, 0, 3]
# case 1
random = mock_service.bad_random.return_value = 49
mock_service.divide.return_value = random / y[0]
mock_service.complicated_function.return_value = Service.divide(y[0]), Service.bad_random() % 2
ret = Service.complicated_function(y[0])
print(ret)
assert ret == (-7.0, 1)
# case 2
with pytest.raises(ZeroDivisionError):mock_service.divide.return_value = random / y[1]
# will be previous value of -7.0 b/c error thrown
mock_service.complicated_function.return_value = Service.divide(y[1]), Service.bad_random() % 2
ret1 = Service.complicated_function(y[1])
print(ret1)
assert ret1 == (-7.0, 1)
# case 3
mock_service.divide.return_value = random / y[2]
mock_service.complicated_function.return_value = Service.divide(y[2]), Service.bad_random() % 2
ret2 = Service.complicated_function(y[2])
print(ret2)
assert ret2 == (16.333333333333332, 1)
示例3: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self):
service = Service()
service.bad_random = mock.Mock(return_value=42)
assert service.complicated_function(3) == (42/3, 0)
service.bad_random = mock.Mock(return_value=43)
assert service.complicated_function(3) == (43/3, 1)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-MichaelParadis,代码行数:10,代码来源:test_service.py
示例4: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self, bad_random):
service = Service()
assert service.complicated_function(5) == (3, 1)
#assert service.complicated_function(0) == (11, 1)
with self.assertRaises(ZeroDivisionError):
service.complicated_function(0)
assert service.complicated_function(-5) == (-3, 1)
示例5: test_complicated
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated(self):
service = Service()
service.bad_random = mock.Mock(return_value = 5)
value = service.complicated_function(5)
self.assertRaises(ZeroDivisionError,service.divide,0)
service.divide = mock.Mock(return_value=4)
return_val = service.complicated_function(2)
assert return_val[0] == 2
assert return_val[1] == 2.5
示例6: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self):
ser = Service()
ser.bad_random = mock.Mock(return_value=15)
re = ser.complicated_function(3)
assert re == (5, 1)
ser.bad_random = mock.Mock(return_value=15)
self.assertRaises(ZeroDivisionError, ser.complicated_function,0)
示例7: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self):
s = Service()
s.bad_random = mock.Mock(return_value=10)
#s.divide = mock.Mock(return_value=2)
r_val = s.complicated_function(5)
assert r_val == (2,0)
self.assertRaises(ZeroDivisionError,s.complicated_function,0)
示例8: TestService
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
class TestService(TestCase):
def setUp(self):
self.service = Service()
@patch("service.Service.bad_random", return_value=10)
def test_bad_random(self, mock_bad_random):
self.assertEqual(self.service.bad_random(),10)
@patch("service.Service.bad_random", return_value=10)
def test_divide(self, mock_bad_random):
self.assertEqual(self.service.divide(2), 5)
try:
self.service.divide(0)
self.assertEqual(True, False)
except:
self.assertEqual(True, True)
try:
self.service.divide("sghf")
self.assertEqual(True, False)
except:
self.assertEqual(True, True)
def test_abs_plus(self):
self.assertEqual(self.service.abs_plus(-1), 2)
self.assertEqual(self.service.abs_plus(0), 1)
self.assertEqual(self.service.abs_plus(1), 2)
try:
self.service.abs_plus("jksdfhhdfbd")
self.assertEqual(True, False)
except:
self.assertEqual(True, True)
@patch("service.Service.bad_random")
def test_complicated_function(self, mock_bad_random):
mock_bad_random.return_value = 10
rv1, rv2 = self.service.complicated_function(2)
self.assertEqual(rv1, 5)
self.assertEqual(rv2, 0)
mock_bad_random.return_value = 11
rv1, rv2 = self.service.complicated_function(2)
self.assertEqual(rv1, 5.5)
self.assertEqual(rv2, 1)
示例9: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self):
service = Service()
service.bad_random = mock.Mock(return_value=8)
# test divide by zero before mock divide
self.assertRaises(ZeroDivisionError,service.divide,0)
# test a normal value
service.divide = mock.Mock(return_value=9)
return_val = service.complicated_function(2)
assert return_val[0]==9
assert return_val[1]==0
示例10: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(divide, bad_random):
newService = Service()
bad_random.return_value = 6
divide.return_value = 3
assert newService.complicated_function(2)[0] == 3
assert newService.complicated_function(2)[1] == 6%2
bad_random.return_value = 6
divide.return_value = -3
assert newService.complicated_function(-2)[0] == -3
assert newService.complicated_function(-2)[1] == 6%-2
divide.return_value = 0
bad_random.return_value = 0
assert newService.complicated_function(6)[0] == 0
assert newService.complicated_function(6)[1] == 0
divide.return_value = None
bad_random.return_value = 4
try:
newService.complicated_function(0)
except ZeroDivisionError:
assert True
divide.return_value = 2
assert newService.complicated_function(2)[0] == 2
assert newService.complicated_function(2)[0] == 0
示例11: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self, mock_bad_random):
mock_bad_random.return_value = 10
import_serv = Service()
compNum = import_serv.complicated_function(5)
self.assertEqual(compNum, (2.0, 0))
示例12: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(bad_randomStub):
bad_randomStub.return_value = 7
serviceTest = Service()
div= serviceTest.complicated_function(5)
assert(div == (7/5,1))
示例13: TestService
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
class TestService(unittest.TestCase):
def setUp(self):
self.service = Service()
@patch('service.Service.bad_random')
def test_bad_random(self, mock_bad_random):
mock_bad_random.return_value = 10
self.assertEqual(self.service.bad_random(), 10)
@patch('service.Service.bad_random')
def test_divide(self, mock_bad_random):
mock_bad_random.return_value = 10
# Divisor and dividend are positive, whole result
self.assertEqual(self.service.divide(5), 2)
# Divisor and dividend are positive, fractional result
self.assertEqual(self.service.divide(20), 0.5)
# Divide by 0
with self.assertRaises(ZeroDivisionError):
self.service.divide(0)
# Positive dividend and negative divisor
self.assertEqual(self.service.divide(-5), -2)
mock_bad_random.return_value = -10
# Negative dividend and positive divisor
self.assertEqual(self.service.divide(5), -2)
# Missing argument
with self.assertRaises(TypeError):
self.service.divide()
def test_abs_plus(self):
# Negative
self.assertEqual(self.service.abs_plus(-1), 2)
# 0
self.assertEqual(self.service.abs_plus(0), 1)
# Positive
self.assertEqual(self.service.abs_plus(1), 2)
# Non-integer
with self.assertRaises(TypeError):
self.service.abs_plus('a')
# No argument
with self.assertRaises(TypeError):
self.service.abs_plus()
@patch('service.Service.divide')
@patch('service.Service.bad_random')
def test_complicated_function(self, mock_bad_random, mock_divide):
mock_divide.return_value = 5
# Sanity test, with even "random" number
mock_bad_random.return_value = 20
(a, b) = self.service.complicated_function(3)
self.assertEqual(a, 5)
self.assertEqual(b, 0)
# Odd "random" number
mock_bad_random.return_value = 19
(a, b) = self.service.complicated_function(3)
self.assertEqual(b, 1)
# Negative even "random" number
mock_bad_random.return_value = -20
(a, b) = self.service.complicated_function(3)
self.assertEqual(b, 0)
# Negative odd "random" number
mock_bad_random.return_value = -19
(a, b) = self.service.complicated_function(3)
self.assertEqual(b, 1)
# No argument
with self.assertRaises(TypeError):
self.service.complicated_function()
示例14: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self, bad_random):
service = Service()
div, rando = service.complicated_function(10)
self.assertEqual(div, 1)
self.assertEqual(rando, 0)
示例15: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import complicated_function [as 别名]
def test_complicated_function(self, mock_bad_random):
mock_bad_random.return_value = 10
service = Service()
assert service.complicated_function(2) == (5, 0)