当前位置: 首页>>代码示例>>Python>>正文


Python Service.divide方法代码示例

本文整理汇总了Python中service.Service.divide方法的典型用法代码示例。如果您正苦于以下问题:Python Service.divide方法的具体用法?Python Service.divide怎么用?Python Service.divide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在service.Service的用法示例。


在下文中一共展示了Service.divide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_complicated_function

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-aabels,代码行数:28,代码来源:test_service.py

示例2: ServiceTest

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-cmackenzie1,代码行数:29,代码来源:test_service.py

示例3: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [as 别名]
    def test_divide(self, bad_random):
        service = Service()

        assert service.divide(1) == 10
        #assert service.divide(0) == "Division by zero"
        with self.assertRaises(ZeroDivisionError):
            service.divide(0)
        assert service.divide(-1) == -10
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-pshn111,代码行数:10,代码来源:test_service.py

示例4: testDivide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [as 别名]
 def testDivide(self, mockDivide):
     mockDivide.return_value = 10
     assert(Service.divide(2) == 10)
     mockDivide.return_value = -10
     assert(Service.divide(-2) == -10)
     mockDivide.return_value = 20
     assert(Service.divide(1) == 20)
     mockDivide.return_value = -20
     assert(Service.divide(-1) == -20)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Z-Red,代码行数:11,代码来源:test_service.py

示例5: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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)       
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Katzesama,代码行数:12,代码来源:test_service.py

示例6: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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

示例7: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Suiteprecure,代码行数:10,代码来源:test_service.py

示例8: test_complicated

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-xgao1,代码行数:12,代码来源:test_service.py

示例9: TestService

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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)       
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-hiufungk,代码行数:45,代码来源:test_service.py

示例10: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-xmzzzz,代码行数:13,代码来源:test_service.py

示例11: test_complicated_function

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Suiteprecure,代码行数:14,代码来源:test_service.py

示例12: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [as 别名]
def test_divide(bad_random):
	newService = Service()

	bad_random.return_value = 0
	assert newService.divide(1) == 0
	assert newService.divide(-1) == 0

	bad_random.return_value = -5
	assert newService.divide(5) == -1
	assert newService.divide(-5) == 1

	bad_random.return_value = 8
	assert newService.divide(-2) == -4
	assert newService.divide(2) == 4
	
	assert newService.divide(10) == 8/10
	assert newService.divide(-10) == -8/10

	try:
		newService.divide(0)
	except ZeroDivisionError:
		assert True	
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-shardul-shah,代码行数:24,代码来源:test_service.py

示例13: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [as 别名]
 def test_divide(self, bad_random):
     service = Service()
     self.assertEqual(service.divide(5), 2)
     self.assertEqual(service.divide(-2), -5)
     self.assertEqual(service.divide(1000000), 10e-6)
     try:
         service.divide(0)
         self.assertTrue(True)
     except Exception as e:
         self.assertEqual(e.__class__, ZeroDivisionError)
     try:
         service.divide("hello")
         self.assertTrue(True)
     except Exception as e:
         self.assertEqual(e.__class__, TypeError)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Hk-tang,代码行数:17,代码来源:test_service.py

示例14: TestService

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [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()
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-corey1994,代码行数:86,代码来源:test_service.py

示例15: test_divide

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import divide [as 别名]
 def test_divide(self, mock_bad_random):
     mock_bad_random.return_value = 10
     service = Service()
     assert service.divide(2) == 5
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-kieter,代码行数:6,代码来源:test_service.py


注:本文中的service.Service.divide方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。