def test_no_redirect(self): # tests a load with a missing import_redirect mod = import_module('yaset.tests.fixtures.no_redirect') with capture_stdout() as capture: import_settings(mod.__dict__) self.assertIn('Error', capture.getvalue())
def file_compare(self, datafile, fn, *args): with capture_stdout() as captured: fn(*args) filename = Path(__file__).parent / f'data/{datafile}' with open(filename.resolve()) as f: expected = f.read() self.assertEqual(expected, captured.getvalue())
def test_bad_redirect(self): # tests a load with an invalid import_redirect entry mod = import_module('yaset.tests.fixtures.bad_redirect') with capture_stdout() as capture: import_settings(mod.__dict__) result = capture.getvalue().split('\n') self.assertIn('yaset could not load', result[0]) self.assertIn('yaset could not load', result[1])
def test_pprint(self): d = { 'foo': 'bar', 'thing': 3, } expected = """{\n "foo": "bar",\n "thing": 3\n}\n""" with capture_stdout() as output: pprint(d) self.assertEqual(expected, output.getvalue())
def test_no_secret(self): # tests a load with a missing secrets file mod = import_module('yaset.tests.fixtures.no_secret') with capture_stdout() as capture: import_settings(mod.__dict__) # import should still work self.assertEqual(mod.DEV_ONE, 1) self.assertEqual(mod.NESTED_ONE, 1) # stdout should include warning about the secret missing result = capture.getvalue() self.assertIn('yaset could not load', result) self.assertIn('secret', result)
def test_pat(self): display_code = Path(__file__).parent / \ '../extras/display_code/decorator.repl' display_code = str(display_code.resolve()) sys.argv = ['pat', '--num', '10', '--highlight', '1-2', display_code] pat = load_command('pat') with capture_stdout() as captured: pat.main() # Get the output content and remove the ESC characters content = captured.getvalue() content = content.replace('\x1b', '') self.assertEqual(PAT_EXPECTED, content)
def test_prat(self): RTFColourizer.reset_background_colour() display_code = Path(__file__).parent / \ '../extras/display_code/decorator.repl' display_code = str(display_code.resolve()) sys.argv = ['prat', '--num', '10', '--highlight', '1-2', '--background', 'ccaa22', display_code] prat = load_command('prat') with capture_stdout() as captured: prat.main() # Get the output content and remove the ESC characters content = captured.getvalue() self.assertEqual(PRAT_EXPECTED, content)
def test_capture_stdout(self): with capture_stdout() as capture: sys.stdout.write('foo\n') self.assertEqual(capture.getvalue(), 'foo\n')