color = self._colors[self._index][0] self._index += 1 color = terminal_interface_win32.windowsColors[color] self.assertEqual(attribute, color) self.assertEqual(len(self.stream.getvalue()), sum(e[1] for e in self._colors[:self._index])) class FakeWin32UncolorizedTest(FakeWin32Test): """Test case to allow doing uncolorized Win32 tests in any environment.""" net = False expected = 'Hello world you! ***' expect_color = False def setUp(self): """Change the local stream's console to None to disable colors.""" super(FakeWin32UncolorizedTest, self).setUp() self.stream._hConsole = None if __name__ == '__main__': # pragma: no cover try: try: unittest.main() except SystemExit: pass finally: unpatch()
basepath = os.path.split(os.path.split(__file__)[0])[0] pwbpath = os.path.join(basepath, 'pwb.py') testbasepath = os.path.join(basepath, 'tests', 'pwb') def check_output(command): return subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] class TestPwb(unittest.TestCase): def setUp(self): self.oldenviron = os.environ.copy() os.environ['PYWIKIBOT2_DIR'] = pywikibot.config.base_dir def tearDown(self): del os.environ['PYWIKIBOT2_DIR'] if 'PYWIKIBOT2_DIR' in self.oldenviron: os.environ['PYWIKIBOT2_DIR'] = self.oldenviron['PYWIKIBOT2_DIR'] def testScriptEnvironment(self): """Make sure the environment is not contaminated, and is the same as the environment we get when directly running a script.""" test = os.path.join(testbasepath, 'print_locals.py') direct = check_output([pypath, test]) vpwb = check_output([pypath, pwbpath, test]) self.assertEqual(direct, vpwb) if __name__ == "__main__": unittest.main(verbosity=10)
# setUp class from datetime import datetime from scripts import archivebot from pywikibot.textlib import TimeStripper # create test methods processed by unittest for code in THREADS: test_name = "test_wikipedia_" + code if code in ['ar', 'ckb', 'en', 'fa', 'frr', 'no', 'pdc', 'pt', 'th', 'ug']: # expected failures - should be fixed dct[test_name] = unittest.expectedFailure(test_method(code)) else: dct[test_name] = test_method(code) return type.__new__(cls, name, bases, dct) class TestArchiveBot(PywikibotTestCase): """Test archivebot script""" __metaclass__ = TestArchiveBotMeta if __name__ == '__main__': try: unittest.main() except SystemExit: pass
pwbpath = os.path.join(basepath, 'pwb.py') testbasepath = os.path.join(basepath, 'tests', 'pwb') def check_output(command): return subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] class TestPwb(unittest.TestCase): def setUp(self): self.oldenviron = os.environ.copy() os.environ['PYWIKIBOT2_DIR'] = pywikibot.config.base_dir def tearDown(self): del os.environ['PYWIKIBOT2_DIR'] if 'PYWIKIBOT2_DIR' in self.oldenviron: os.environ['PYWIKIBOT2_DIR'] = self.oldenviron['PYWIKIBOT2_DIR'] def testScriptEnvironment(self): """Make sure the environment is not contaminated, and is the same as the environment we get when directly running a script.""" test = os.path.join(testbasepath, 'print_locals.py') direct = check_output([pypath, test]) vpwb = check_output([pypath, pwbpath, test]) self.assertEqual(direct, vpwb) if __name__ == "__main__": unittest.main(verbosity=10)