本文整理汇总了Python中service.Service.bad_random方法的典型用法代码示例。如果您正苦于以下问题:Python Service.bad_random方法的具体用法?Python Service.bad_random怎么用?Python Service.bad_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.Service
的用法示例。
在下文中一共展示了Service.bad_random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bad_random
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_bad_random(self, randintMock, mockOpen):
# integers
mockOpen.return_value = MockFile([1, 4, 7])
randintMock.return_value = 2
assert Service.bad_random() == 2
randintMock.assert_called_once_with(0, 2)
randintMock.reset_mock()
# empty
mockOpen.return_value = MockFile([])
randintMock.return_value = -1
assert Service.bad_random() == -1
randintMock.assert_called_once_with(0, -1)
randintMock.reset_mock()
# float
mockOpen.return_value = MockFile([5.2])
randintMock.return_value = 0
assert Service.bad_random() == 0
randintMock.assert_called_once_with(0, 0)
randintMock.reset_mock()
# non-numeric values
mockOpen.return_value = MockFile([1, "a", 7])
self.assertRaises(ValueError, Service.bad_random)
mockOpen.reset_mock()
示例2: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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 bad_random [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)
示例4: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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
示例5: test_divide
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_divide(self):
ser = Service()
ser.bad_random = mock.Mock(return_value=20)
re = ser.divide(10)
assert re == 2
ser.bad_random = mock.Mock(return_value=20)
re = ser.divide(-10)
assert re == -2
ser.bad_random = mock.Mock(return_value=20)
self.assertRaises(ZeroDivisionError, ser.divide,0)
示例6: test_divide
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_divide(self):
s = Service()
s.bad_random = mock.Mock(return_value=10)
r_val = s.divide(5)
assert r_val == 2
s.bad_random = mock.Mock(return_value=1)
#r_val2 = s.divide(0)
self.assertRaises(ZeroDivisionError,s.divide,0)
'''s.bad_random = mock.Mock(return_value=None)
示例7: test_bad_random
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_bad_random(self, mock_service):
mock_service.return_value = 199
assert Service.bad_random() == 199
mock_service.return_value = 0
assert Service.bad_random() == 0
mock_service.return_value = -199
assert Service.bad_random() == -199
mock_service.return_value = "jdsalkd"
assert Service.bad_random() is not int
return
示例8: test_bad_random
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_bad_random(bad_random):
newService = Service()
bad_random.return_value = 3
assert newService.bad_random() == 3
bad_random.return_value = 0
assert newService.bad_random() == 0
bad_random.return_value = 10
assert newService.bad_random() == 10
示例9: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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)
示例10: test_divide
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_divide(self):
service = Service()
service.bad_random = mock.Mock(return_value=9)
return_val = service.divide(2)
assert return_val == 4.5
# trying to divide 0
self.assertRaises(ZeroDivisionError,service.divide,0)
示例11: test_bad_random
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_bad_random(self):
file_content_mock1 = """10\n12\n14\n16\n18\n20\n30"""
#fake_file_path = 'file/path/mock'
newfile = mock_open(read_data=file_content_mock1)
with patch('service.open',newfile,create=True) :
number1 = Service.bad_random()
expected = len(file_content_mock1.split('\n'))
assert 0 <= number1 < expected
示例12: test_complicated
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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
示例13: test_complicated_function
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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
示例14: test_divide
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [as 别名]
def test_divide(self):
service = Service()
service.bad_random = mock.Mock(return_value=42)
y = 3
assert service.divide(y) == 42 / y
y2 = -10
assert service.divide(y2) == 42 / y2
assert service.divide(2) == 21
with pytest.raises(ZeroDivisionError):service.divide(0)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-MichaelParadis,代码行数:14,代码来源:test_service.py
示例15: TestService
# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import bad_random [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)