def verifyAnimationCount(unittest, parentWidget, expectedCount): animatorList = parentWidget.find_elements_by_xpath( ".//div[@qxclass='skel.boundWidgets.Animator']") animatorCount = len(animatorList) print "Animator list count=", animatorCount unittest.assertEqual(animatorCount, expectedCount, "Animator count does not match expected count")
def test_something(self): # Use the assert* functions to determine the outcome of a test. unittest.assertEqual(1,1) unittest.assertNotEqual(1,0) unittest.assertTrue(1 == 1) unittest.assertFalse(1 == 0) unittest.assertIs(a, b) unittest.assertIsNot(a, c) unittest.assertIsNone(None) unittest.assertIsNotNone(a) unittest.assertIn(1, a) unittest.assertNotIn(4, b) unittest.assertIsInstance(c, list) unittest.assertNotIsInstance(d, list) unittest.assertRaises() unittest.assertRaisesRegex() unittest.assertWarns() unittest.assertWarnsRegex() unittest.assertLogs() unittest.assertAlmostEqual() unittest.assertNotAlmostEqual() unittest.assertGreater() unittest.assertGreaterEqual() unittest.assertLess() unittest.assertLessEqual() unittest.assertRegex() unittest.assertNotRegex() unittest.assertCountEqual()
def test_part_offset(self): control_list = helper.checkPartOffset(self.scores) for s_control in control_list: for element in s_control: if not element: control_resulut = False control_result = True breakpoint() unittest.assertEqual(control_result, True)
def __compare_dictionaries(self, unittest, result, expected_result, msg_base = ''): """Evaluates the returned results.""" unittest.assertEqual(len(expected_result), len(result), '{}: The expected result dict contains {} entries (for 4-connectedness), instead found {}.'.format(msg_base, len(expected_result), len(result))) for key, value in result.items(): unittest.assertTrue(key in expected_result, '{}: Region border {} unexpectedly found in expected results.'.format(msg_base, key)) if key in expected_result: unittest.assertAlmostEqual(value[0], expected_result[key][0], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon) unittest.assertAlmostEqual(value[1], expected_result[key][1], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon) unittest.assertGreater(value[0], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key)) unittest.assertGreater(value[1], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key)) for key, value in expected_result.items(): unittest.assertTrue(key in result, '{}: Region border {} expectedly but not found in results.'.format(msg_base, key))
def __compare_dictionaries(self, unittest, result, expected_result, msg_base = ''): """Evaluates the returned results.""" unittest.assertEqual(len(expected_result), len(result), '{}: The expected result dict contains {} entries (for 4-connectedness), instead found {}.'.format(msg_base, len(expected_result), len(result))) for key, value in result.iteritems(): unittest.assertTrue(key in expected_result, '{}: Region border {} unexpectedly found in results.'.format(msg_base, key)) if key in expected_result: unittest.assertAlmostEqual(value[0], expected_result[key][0], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon) unittest.assertAlmostEqual(value[1], expected_result[key][1], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon) unittest.assertGreater(value[0], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key)) unittest.assertGreater(value[1], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key)) unittest.assertLessEqual(value[0], 1.0, '{}: Encountered a weight {} > 1.0 for key {}.'.format(msg_base, value, key)) unittest.assertLessEqual(value[1], 1.0, '{}: Encountered a weight {} > 1.0 for key {}.'.format(msg_base, value, key)) for key, value in expected_result.iteritems(): unittest.assertTrue(key in result, '{}: Region border {} expectedly but not found in results.'.format(msg_base, key))
def test_population_density_dessert(self): request = requests.get("http://perlman.mathcs.carleton.edu:5101/home?demographic=population_density&interest=dessert") unittest.assertEqual(json.loads(request.json()), {'urban': {'apple cobbler': .71, 'blondies': .22, 'brownies': .3, 'carrot cake': .23, 'cheesecake': .04, 'cookies': .72, 'fudge': .14, 'ice cream': .53, 'peach cobbler': .73, 'none': .07, 'other': .3}, 'suburban': {'apple cobbler': .69, 'blondies': .45, 'brownies': .53, 'carrot cake': .25, 'cheesecake': .16, 'cookies': .73, 'fudge': .24, 'ice cream': .55,'peach cobbler': .8, 'none': .04, 'other': .09}, 'rural': {'apple cobbler': .65, 'blondies': .33, 'brownies': .42, 'carrot cake': .37, 'cheesecake': .15, 'cookies': .66, 'fudge': .35, 'ice cream': .87, 'peach cobbler': .43, 'none': .09, 'other': .11} })
def assert_equal(self, unittest, first, second, msg, name_screen_shot): """ :param first: 第一个比较字符串 :param second: 第二个比较字符串 :param msg: 断言信息 :param name_ScreenShot:截图名称 :return: """ try: unittest.assertEqual(first, second, msg) # except Exception: # pass finally: self.screen_shot(name_screen_shot) time.sleep(5) pass
def adb_connect(unittest, serial): """Context manager for an ADB connection. This automatically disconnects when done with the connection. """ output = subprocess.check_output(['adb', 'connect', serial]) unittest.assertEqual(output.strip(), 'connected to {}'.format(serial)) try: yield finally: # Perform best-effort disconnection. Discard the output. subprocess.Popen(['adb', 'disconnect', serial], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
def test_argumentPassing(self): assertEqual(self.factoryOne.getWorld( ), self.wrld) assertEqual(self.factoryTwo.getWorld( ), self.wrld) assertEqual(self.factoryOne.getArg(0), 4) assertEqual(self.factoryOne.getArg(1), 12) assertRaises(IndexError, self.factoryOne.getArg, 2) assertRaises(IndexError, self.factoryTwo.getArg, 0) reactor.stop()
def adb_connect(unittest, serial): """Context manager for an ADB connection. This automatically disconnects when done with the connection. """ output = subprocess.check_output(["adb", "connect", serial]) unittest.assertEqual(output.strip(), "connected to {}".format(serial).encode("utf8")) try: yield finally: # Perform best-effort disconnection. Discard the output. subprocess.Popen(["adb", "disconnect", serial], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
def test_age_group_pie(self): request = requests.get("http://perlman.mathcs.carleton.edu:5101/home?demographic=age_group&interest=pie") unittest.assertEqual(json.loads(request.json()), {'18-29': {'pumpkin': .7, 'apple': .2, 'buttermilk': .02, 'cherry': .05, 'chocolate': .09, 'coconut cream': .01, 'key lime': 0, 'peach': .02, 'pecan': .3, 'sweet potato': .03, 'none': .21 , 'other': .11}, '30-44': {'pumpkin': .73, 'apple': .32, 'buttermilk': .01, 'cherry': .12, 'chocolate': .01, 'coconut cream': .02, 'key lime': .01, 'peach': .11, 'pecan': .21,'sweet potato': .05, 'none': .12, 'other': .2}, '45-59': {'pumpkin': .71, 'apple': .32, 'buttermilk': .03, 'cherry': .1, 'chocolate': .02, 'coconut cream': 0, 'key lime': .03, 'peach': .11, 'pecan': .21,'sweet potato': .05, 'none': .08, 'other': .32}, '60+': {'pumpkin': .8, 'apple': .3, 'buttermilk': .02, 'cherry': .09, 'chocolate': .03, 'coconut cream': .01, 'key lime': 0, 'peach': .21, 'pecan': .21,'sweet potato': .05, 'none': .04, 'other': .12}, })
def testHangPostFromDict(self): api = tumblr.Api('testy-workpls') d = api.read(id=17390096011) hp = HangPost(d) unittest.assertEqual(hp.id, 17390096011) unittest.assertEqual(hp.photo, 'http://27.media.tumblr.com/tumblr_lz6q0gDfhG1qh3h2lo1_500.jpg') unittest.assertEqual(hp.tags, [u'i wish', u'tagssss', u'whee'])
def test_mlpredict(): year_plot_list = [] for yr in range(2013, 2018): year_plot_list.append( pd.read_csv(mapping_funcs.DATA_DIR + '/2013.csv').shape[0]) mlpredict.year_plot(year_plot_list, TEST_OUTPUT) df_2017 = pd.read_csv(mapping_funcs.DATA_DIR + "/2017.csv") mlpredict.month_plot(df_2017, TEST_OUTPUT) mlpredict.weekday_plot(df_2017, TEST_OUTPUT) mlpredict.weather_plot(df_2017, TEST_OUTPUT) mlpredict.road_plot(df_2017, TEST_OUTPUT) mlpredict.light_plot(df_2017, TEST_OUTPUT) mlpredict.ml_prediction(df_2017, TEST_OUTPUT) unittest.assertEqual( (os.path.isfile(TEST_OUTPUT + '/year_plot.png') and os.path.isfile(TEST_OUTPUT + '/month_plot.png') and os.path.isfile(TEST_OUTPUT + 'weekday_plot.png') and os.path.isfile(TEST_OUTPUT + 'weather_plot.png') and os.path.isfile(TEST_OUTPUT + 'road_plot.png') and os.path.isfile(TEST_OUTPUT + 'light_plot.png') and os.path.isfile(TEST_OUTPUT + 'weather_factor_importance.png')), True, "Missing one or more outputs")
def test_expected_failure(self): unittest.assertEqual(2, 3)
def test_basicInit(self): o = self.world.getByID(self, 1) unittest.assertNotEqual(o, None) o = self.world.getByID(self, 14890141) unittest.assertEqual(o, None)
def verifier(graph, start, end): forward = test_func(graph, start, end) reverse = test_func(graph, end, start) unittest.assertEqual(forward, reverse[::-1]) return func(graph, start, end)
def get_row_count(unittest, table_name, count): test_sql = "SELECT * FROM " + table_name result = exec_sql(test_sql) unittest.assertEqual(len(result), count, table_name)
def verifyAnimationCount(unittest, parentWidget, expectedCount): animatorList = parentWidget.find_elements_by_xpath( ".//div[@qxclass='skel.boundWidgets.Animator']" ) animatorCount = len( animatorList ) print "Animator list count=", animatorCount unittest.assertEqual( animatorCount, expectedCount, "Animator count does not match expected count")
def verifyAnimatorUpperBound(unittest, driver, expectedCount, animatorName): fullId = animatorName + "AnimatorUpperBound" animatorLabel = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, fullId ) ) ) upperBound = animatorLabel.text print "Animator upper bound=", upperBound, " expected bound=", expectedCount unittest.assertEqual( upperBound, str(expectedCount), "Animator upper bound was not correct")
def test_row_count(unittest, table_name, count, condition=''): test_sql = "SELECT * FROM " + table_name if condition: test_sql += ' WHERE ' + condition result = exec_sql(test_sql) unittest.assertEqual(len(result), count, table_name)
self.assertEqual(encode_resistor_colors("4.7k ohms"), "yellow violet red gold") def test_resistors_test9(self): self.assertEqual(encode_resistor_colors("10k ohms"), "brown black orange gold") def test_resistors_test10(self): self.assertEqual(encode_resistor_colors("22k ohms"), "red red orange gold") def test_resistors_test11(self): self.assertEqual(encode_resistor_colors("47k ohms"), "yellow violet orange gold") def test_resistors_test12(self): self.assertEqual(encode_resistor_colors("100k ohms"), "brown black yellow gold") def test_resistors_test13(self): self.assertEqual(encode_resistor_colors("330k ohms"), "orange orange yellow gold") def test_resistors_test14(self): self.assertEqual(encode_resistor_colors("1M ohms"), "brown black green gold") def test_resistors_test15(self): self.assertEqual(encode_resistor_colors("2M ohms"), "red black green gold") def test_resistors_test16(self): self.assertEqual(encode_resistor_colors("470M ohms"), "yellow violet violet gold") if __name__ == '__main__': unittest.assertEqual(encode_resistor_colors("10 ohms"), "brown black black gold") # encode_resistor_colors("10 ohms")
def test_random(self): request = requests.get("http://perlman.mathcs.carleton.edu:5101/random/") unittest.assertEqual(len(json.loads(request.json())), 21)
def assert_same_node(unittest, n1, n2): if n1 and n2: unittest.assertEqual(n1.value, n2.value) else: unittest.assertEqual(n1, n2)
import requests import unittest url = "http://mkapioauth2.modalku.co.id/api/Account" headers = { 'authorization': "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InJvbmFsZC5pLndpamF5YUBnbWFpbC5jb20iLCJzdWIiOiJyb25hbGQuaS53aWpheWFAZ21haWwuY29tIiwicm9sZSI6IkludmVzdG9yIiwiaXNzIjoiaHR0cDovL2F1dGhzdGFnaW5nLm1vZGFsa3UuY28uaWQvIiwiYXVkIjoiSXBob25lIiwiZXhwIjoxNDY5NjAwMTE3LCJuYmYiOjE0Njk1OTgzMTd9.65FMfde6hjPBxjOT_Q8jrPx1kMCmrrmx-a05vcXY2dM" } response = requests.request("GET", url, headers=headers) state = response.status_code unittest.assertEqual(200, state) print(response.text)