def test_fail(self): with capture_out() as (stdout, stderr): with self.assertRaises(Failure): examinee.fail(msg='foo bar') self.assertEqual('ERROR: foo bar', stdout.getvalue().strip()) self.assertTrue(len(stderr.getvalue()) == 0)
def test_fail(): with capture_out() as (stdout, stderr): with pytest.raises(Failure): examinee.fail(msg='foo bar') assert 'ERROR: foo bar' == stderr.getvalue().strip() assert len(stdout.getvalue()) == 0
def test_get_kubecfg_should_fail_on_absent_file(self): self.fixture_args.kubeconfig = 'no such file' # silence output (we do not care about it, though) with capture_out() as (stdout, stderr): with self.assertRaises(Failure): self.examinee.get_kubecfg()
def test_fail_on_absent_input_file(self): test_file_path = 'file_that_should_not_exist' self.assertTrue(os.path.isfile(test_file_path) is False) with capture_out(): with self.assertRaises(Failure) as se: examinee.process_version(input_file=test_file_path, operation='set_build_metadata', build_metadata='test') self.assertNotEqual(se.exception.code, 0)
def test_fail_on_output_file_with_absent_parent_directory(self): test_file_path = 'directory_that_should_not_exist/test_file' with capture_out(): with self.assertRaises(Failure) as se: examinee.process_version(version_string='1.1.1', output_file=test_file_path, operation='set_build_metadata', build_metadata='test') self.assertNotEqual(se.exception.code, 0)
def test_info_with_quiet(self): class Args(object): pass args = Args() args.quiet = True import ctx ctx.args = args with capture_out() as (stdout, stderr): examinee.info(msg='should not be printed') self.assertTrue(len(stdout.getvalue()) == 0) self.assertTrue(len(stderr.getvalue()) == 0)
def test_ensure_not_empty(self): result = examinee.ensure_not_empty('foo') self.assertEqual('foo', result) forbidden = ['', None, [], ()] for value in forbidden: with capture_out() as (stdout, stderr): with self.assertRaises(Failure): examinee.ensure_not_empty(value) self.assertIn('must not be empty', stdout.getvalue().strip()) self.assertTrue(len(stderr.getvalue()) == 0)
def test_ensure_file_exists(self): import sys existing_file = sys.executable result = examinee.ensure_file_exists(existing_file) self.assertEqual(existing_file, result) with capture_out() as (stdout, stderr): with self.assertRaises(Failure): examinee.ensure_file_exists('no such file, I hope') self.assertIn('not an existing file', stdout.getvalue().strip()) self.assertTrue(len(stderr.getvalue()) == 0) # should also work with pathlib.Path existing_file = pathlib.Path(existing_file) self.assertEqual(examinee.ensure_file_exists(existing_file), existing_file)
def test_info(self): with capture_out() as (stdout, stderr): examinee.info(msg='test abc') self.assertEqual('INFO: test abc', stdout.getvalue().strip()) self.assertTrue(len(stderr.getvalue()) == 0)
def test_success(): with capture_out() as (stdout, stderr): examinee.success('xxx') assert 'SUCCESS: xxx' == stdout.getvalue().strip() assert len(stderr.getvalue()) == 0
def test_info(): with capture_out() as (stdout, stderr): examinee.info(msg='test abc') assert 'INFO: test abc' == stdout.getvalue().strip() assert len(stderr.getvalue()) == 0
def test_fail_on_empty_stdin(self): with capture_out(): with self.assertRaises(Failure) as se: examinee.process_version(operation='set_build_metadata', build_metadata='test') self.assertNotEqual(se.exception.code, 0)