"""Mechanical Turk tests.""" test_loader = unittest.TestLoader() test_suite = test_loader.discover("parlai/mturk/core/test/") return test_suite @_clear_cmdline_args def oncommit(): """Tests needed to pass Continuous Integration.""" test_suite = unittest.TestSuite() test_suite.addTests(short()) changed_files = testing_utils.git_changed_files(skip_nonexisting=False) if any('parlai/mturk' in fn for fn in changed_files): # if any mturk stuff changed, run those tests too test_suite.addTests(mturk()) return test_suite @_clear_cmdline_args def full(): """All tests.""" test_suite = unittest.TestSuite() test_suite.addTests(short()) test_suite.addTests(integration()) test_suite.addTests(mturk()) return test_suite if __name__ == '__main__': unittest.run(oncommit())
#coding:utf-8 import unittest from desired_capabilities import get_desired_capabilities import time from selenium import webdriver from appium import webdriver class AtTests(unittest.TestCase): def setUp(self): desired_caps=get_desired_capabilities() self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) time.sleep(2) def tearDown(self): self.driver.quit() def test_homepage_01(self): print(测试成功) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests) unittest.run(suite)
def main(): unittest.run(OdeSolverTests)
# WST 4 2 6 -- last pick self.assertTrue(results[0:1]['code'][0] == 'NAB') self.assertTrue(results[-1:]['code'][0] == 'WST') def test_rank_ROE_avg_3_returns_correct_top(self): roe_rank = { 'name': 'roe', 'max': 0.8, 'average': 3, 'ascending': False } # Push last 3 years into a list date_array = [ datetime.date(self.current_year - i, 6, 20) for i in range(3)] data = pd.DataFrame({ 'code': ['ANZ'] * 3 + ['CBA'] * 3 + ['NAB'] * 3, 'roe': [0.1, 0.2, 0.5] + [0.7, 0.1, 0.2] + [0.1, 0.2, 0.4]}, index=pd.to_datetime(date_array * 3), dtype=float ) ranker = Ranker(data, [roe_rank], [], limit=50) results = ranker.process() self.assertTrue(results[0:1]['code'][0] == 'CBA') self.assertTrue(results[-1:]['code'][0] == 'NAB') if __name__ == '__main__': unittest.run()
import unittest def suite(): test_suite = unittest.TestLoader().discover('.', pattern='*_test.py') return test_suite if __name__ == '__main__': unittest.run(suite())
def main(): unittest.run(RecorderTests)
def main(): unittest.run(DomainTests)
def main(): unittest.run(StatisticsTests)
def main(): unittest.run(StateEnumTests)
u"I'm No. 1 bitches.", u"Suck an egg.", ] actual_sentences = self.parser.sentences(text) self.assertEqual(len(actual_sentences), len(expected_sentences)) for actual, expected in zip(actual_sentences, expected_sentences): self.assertEqual(actual, expected) def test_smartquote_ending_sentence(self): text = u"And he says, ‘Oh, I’m going to get to?’ And I said, ‘Of course you are.’ And he says, ‘Well, good, that’s why I came to Michigan." expected_sentences = [ u"And he says, ‘Oh, I’m going to get to?’", u"And I said, ‘Of course you are.’", u"And he says, ‘Well, good, that’s why I came to Michigan.", ] actual_sentences = self.parser.sentences(text) self.assertEqual(len(actual_sentences), len(expected_sentences)) for actual, expected in zip(actual_sentences, expected_sentences): self.assertEqual(actual, expected) if __name__ == '__main__': unittest.run(verbosity=2)
import unittest import sys def func(i): return 1/i class MyTest(unittest.TestCase): def _helper(self,a): try: return func(a) except Exception: sys.exit() def test1(self): ret=self._helper(0) self.assertEqual(2,ret) def test2(self): ret=self._helper(1) self.assertEqual(1,ret) if __name__ == '__main__': unittest.run(failfast=True)
def main(): unittest.run(ModelTests)
#!/usr/bin/env python2 import unittest from pymaptools import enumerator class TestEnum(unittest.TestCase): def test_values(self): i = enumerator() self.assertEqual(i["cat"], 0) self.assertEqual(i["dog"], 1) self.assertEqual(i["cat"], 0) self.assertEqual(len(i), 2) if __name__ == "__main__": unittest.run(verbose=True)
cls.morouns = {} with open(os.path.join(_dir, "morouns.txt"), "r") as fp: lines = fp.readlines() cls.morouns["title"] = _u(lines[0]) cls.morouns["text"] = _u("".join(lines[1:])) def test_autotech_summary(self): expected_summary = _read_expected_summary("autotech_s.txt") actual_summary = summarize(self.autotech["title"], self.autotech["text"]) for actual, expected in zip(actual_summary, expected_summary): self.assertEqual(actual.replace("\n", ""), _clean_sentence(expected)) def test_misty_summary(self): expected_summary = _read_expected_summary("misty_s.txt") actual_summary = summarize(self.misty["title"], self.misty["text"]) for actual, expected in zip(actual_summary, expected_summary): self.assertEqual(actual.replace("\n", ""), _clean_sentence(expected)) def test_morouns_summary(self): expected_summary = _read_expected_summary("morouns_s.txt") actual_summary = summarize(self.morouns["title"], self.morouns["text"]) for actual, expected in zip(actual_summary, expected_summary): self.assertEqual(actual.replace("\n", ""), _clean_sentence(expected)) if __name__ == "__main__": unittest.run(verbosity=2)
def main(): unittest.run(MeasurementTests)
"""Mechanical Turk tests.""" test_loader = unittest.TestLoader() test_suite = test_loader.discover("parlai/mturk/core/test/") return test_suite @_clear_cmdline_args def travis(): """Tests needed to pass Travis.""" test_suite = unittest.TestSuite() test_suite.addTests(short()) changed_files = utils.git_changed_files(skip_nonexisting=False) if any('parlai/mturk' in fn for fn in changed_files): # if any mturk stuff changed, run those tests too test_suite.addTests(mturk()) return test_suite @_clear_cmdline_args def full(): """All tests.""" test_suite = unittest.TestSuite() test_suite.addTests(short()) test_suite.addTests(integration()) test_suite.addTests(mturk()) return test_suite if __name__ == '__main__': unittest.run(travis())
def main(): unittest.run(LexArraySetTests)
def unittests(): """ Short tests. Runs on CircleCI on every commit. Returns everything in the tests root directory. """ test_loader = unittest.TestLoader() test_suite = test_loader.discover('tests') test_suite = _circleci_parallelism(test_suite) return test_suite @_clear_cmdline_args def mturk(): """Mechanical Turk tests.""" test_loader = unittest.TestLoader() test_suite = test_loader.discover("parlai/mturk/core/test/") return test_suite @_clear_cmdline_args def internal_tests(): """Internal Tests""" test_loader = unittest.TestLoader() test_suite = test_loader.discover("parlai_internal/tests") return test_suite if __name__ == '__main__': unittest.run(unittests())
class TestDemo(unittest.TestCase): def setUp(self): pass def test_Demo1(self): xmlhead = xxxxxx xmlbody = xxxxxx data = {'xmlhead' : xmlhead, 'xmlbody' : xmlbody} #xmlhead、xmlbody为xml格式的报文头、报文体 url = 'http://xxxxxx' result = requests.post(url,data=data) try: self.assertEqual(result.status_code, 200) print ("用例测试通过") except Exception as e: print (e) print ("用例测试不通过") #之前写的是格式为print (e, '用例测试不通过'),打印出来的语句非utf-8格式,因此在此写了两个print def tearDown(self): pass if __name__ == '__main__': unittest.run() import xlrd class ReadXml(object): def __init__(self,path = ''): self.url = xlrd.open_workbook(path) #打开文件 def get_Datasheet_by_name(self,sheet): self.sheet = self.url.sheet_by_name(sheet) #获取sheet页的名字 return self.DataList() def DataList(self): list = [] for row in range(0, self.sheet.nrows): #nrows()方法为获取某一sheet页的行数 resu = self.sheet.row_values(row) #row_values()批量获取单元格数据 list.append(resu) return list import read_excal def get_data(self,sheet,row,col): filepath = read_excal.ReadXml('D:\xx\xx\\xx.xlsx') #在具体文件名前面可以加‘\’,但在本地运行时有时加一个'\'保存,所以加了'\\'确保程序正常运行 ResultData = filepath.get_Datasheet_by_name(sheet) return ResultData import requests import unittest import base #导入base模块 class TestDemo(unittest.TestCase): def setUp(self): self.xmlhead = base.get_data('xmlhead') #读取'xmlhead'页的所有数据 self.xmlbody = base.get_data('xmlbody') #读取'xmlbody'页的所有数据 def test_Demo1(self): xmlhead = self.xmlhead[0][0] #获取'xmlhead'页的第1行第1列数据 xmlbody = self.xmlbody[13][1] #获取'xmlbody'页的第14行第2列数据 data = {'xmlhead' : xmlhead, 'xmlbody' : xmlbody} #xmlhead、xmlbody为xml格式的报文头、报文体
from traits.testing.api import UnittestTools from traitsui.api import Item, TupleEditor, View from traitsui.tests._tools import ( create_ui, skip_if_null, ) class DummyModel(HasStrictTraits): """ Dummy model with a Tuple trait. """ data = Tuple(Float, Float, Str) traits_view = View(Item(name="data", editor=TupleEditor())) class TestTupleEditor(UnittestTools, unittest.TestCase): @skip_if_null def test_value_update(self): # Regression test for #179 model = DummyModel() with create_ui(model) as ui: with self.assertTraitChanges(model, "data", count=1): model.data = (3, 4.6, "nono") if __name__ == "__main__": unittest.run()