Python Service.abs_plus方法代码示例(pythonservice.abs_plus方法的典型用法代码示例)

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


Python Service.abs_plus方法代码示例(pythonservice.abs_plus方法的典型用法代码示例)

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

示例1: testDivide

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

示例2: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
def test_abs_plus():
    serviceTest = Service()
    testValue = serviceTest.abs_plus(-5)
    assert(testValue == 6)

    testValue = serviceTest.abs_plus(0)
    assert(testValue == 1)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-htruong1,代码行数:9,代码来源:test_service.py

示例3: ServiceTest

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

示例4: test_abs_plus

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

	assert newService.abs_plus(-10) == (abs(-10) + 1)
	assert newService.abs_plus(10) == (abs(10) + 1)
	assert newService.abs_plus(0) == (abs(0) + 1)
	assert newService.abs_plus(3.14) == (abs(3.14) + 1)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-shardul-shah,代码行数:9,代码来源:test_service.py

示例5: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
 def test_abs_plus(self):
     s = Service()
     #s.bad_random = mock.Mock(return_value=10)
     r_val = s.abs_plus(-100)
     assert r_val == 101
     
     r_val1 = s.abs_plus(1e-9)
     assert r_val1 == 1e-9+1
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-xmzzzz,代码行数:10,代码来源:test_service.py

示例6: test_abs

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
 def test_abs(self):
     service = Service()
     self.assertEqual(service.abs_plus(-5), 6)
     self.assertEqual(service.abs_plus(10000000), 10000001)
     self.assertEqual(service.abs_plus(0), 1)
     try:
         service.abs_plus("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,代码行数:12,代码来源:test_service.py

示例7: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
    def test_abs_plus(self):
        service = Service()
        return_val = service.abs_plus(3)
        assert return_val == 4

        return_val1 = service.abs_plus(-1)
        assert return_val1 == 2

        return_val2 = service.abs_plus(0)
        assert return_val2 == 1

        # cannot abs a string
        self.assertRaises(TypeError,service.abs_plus,"")
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Suiteprecure,代码行数:15,代码来源:test_service.py

示例8: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
def test_abs_plus():	
	serv = Service()

	test_outputs = [1, 1.1, 1.1, 2, 2, 3, 3, 11, 11, 1001, 1001]

	# test all inputs
	for i in range(0, len(test_inputs)):
		result = serv.abs_plus(test_inputs[i])
		assert(result == test_outputs[i])
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-IanWark,代码行数:11,代码来源:test_service.py

示例9: TestService

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

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
 def test_abs_plus(self, x):
     import_serv = Service()
     absNum = import_serv.abs_plus(-4)
     self.assertEqual(absNum, 5)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-machung21,代码行数:6,代码来源:test_service.py

示例11: TestService

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

示例12: test_abs_plus

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

示例13: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
 def test_abs_plus(self):
     service = Service()
     
     assert service.abs_plus(0) == 1
     assert service.abs_plus(-1) == 2
     assert service.abs_plus(1) == 2
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-MichaelParadis,代码行数:8,代码来源:test_service.py

示例14: ServiceTests

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
class ServiceTests(unittest.TestCase):
	def setUp(self):
		self.instance = Service()
		
	def _testDivideWithValues(self, mockValue, divideArg, expected, badRandomMock):
		badRandomMock.return_value = mockValue
		assert self.instance.divide(divideArg) == expected
	
	@patch("service.Service.bad_random")
	def test_divide(self, badRandomMock):
		self._testDivideWithValues(1, 5, 0.2, badRandomMock)
		self._testDivideWithValues(0, 5, 0, badRandomMock)
		self._testDivideWithValues(5, 5, 1, badRandomMock)
		self._testDivideWithValues(-3, 5, -0.6, badRandomMock)
		self._testDivideWithValues(-2, -4, 0.5, badRandomMock)
		self._testDivideWithValues(20000, -10000, -2, badRandomMock)
		
		badRandomMock.return_value = 1
		self.assertRaises(ZeroDivisionError, self.instance.divide, 0)
		
	def test_abs_plus(self):
		assert self.instance.abs_plus(-1) == 2
		assert self.instance.abs_plus(1) == 2
		assert self.instance.abs_plus(0) == 1
		assert self.instance.abs_plus(-2) == 3
		assert self.instance.abs_plus(-2147483648) == 2147483649
		assert self.instance.abs_plus(2147483647) == 2147483648
		assert self.instance.abs_plus(0.55555) == 1.55555
		assert self.instance.abs_plus(-0.55555) == 1.55555
		self.assertRaises(TypeError, self.instance.abs_plus, "a")

	def test_complicated_function(self):
		self.instance.divide = MagicMock(25)
		self.assertRaises(TypeError, self.instance.complicated_function, 25)
		
		self.instance.divide = MagicMock(0)
		self.assertRaises(TypeError, self.instance.complicated_function, 9)
		
		self.instance.divide = MagicMock(100)
		self.assertRaises(TypeError, self.instance.complicated_function, 2)
		
		self.instance.divide = MagicMock(-25)
		self.assertRaises(TypeError, self.instance.complicated_function, 2)

	@patch("builtins.open")
	@patch("random.randint")
	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()
		
	def test_bad_random_file_error(self):
		self.assertRaises(FileNotFoundError, Service.bad_random)
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-amalik2,代码行数:77,代码来源:test_service.py

示例15: test_abs_plus

# 需要导入模块: from service import Service [as 别名]
# 或者: from service.Service import abs_plus [as 别名]
 def test_abs_plus(self):
     ser = Service()
     re = ser.abs_plus(10)
     assert re == 11
     re = ser.abs_plus(-20)
     assert re == 21 
开发者ID:cmput401-fall2018,项目名称:web-app-ci-cd-with-travis-ci-Katzesama,代码行数:8,代码来源:test_service.py

本文标签属性:

示例:示例图

代码:代码转换器

Python:python菜鸟教程

Service:service是什么意思车上仪表盘

abs_plus:abs_plus

上一篇:冬日浪漫爱情电影,快邀请你的ta一起冲!(5部适合圣诞看的冬季电影)(5部适合圣诞看的冬季电影,有哪些故事发生在冬季?)
下一篇:C# CSharp.Location类代码示例(c#中microsoft.codeanalysis.csharp.location类的典型用法)

为您推荐