From 565451036364509ba00d7acfee065b4b6f896b3e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 13 Apr 2017 21:48:32 +0300 Subject: Use asserts from yarnutils Also, drop code from yarnhelper that is no longer needed. --- 900-implements.yarn | 14 +++++++------- yarnhelper.py | 21 --------------------- yarnhelper_tests.py | 21 --------------------- 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/900-implements.yarn b/900-implements.yarn index 4e64995..72427a5 100644 --- a/900-implements.yarn +++ b/900-implements.yarn @@ -19,7 +19,7 @@ h = yarnhelper.YarnHelper() expected = vars['http_status'] actual = int(get_next_match()) - h.assertEqual(expected, actual) + assertEqual(expected, actual) IMPLEMENTS THEN HTTP body matches "(.*)" h = yarnhelper.YarnHelper() @@ -27,7 +27,7 @@ sys.stdout.write('Body:\n{}'.format(repr(body))) pattern = get_next_match() m = re.search(pattern, body) - h.assertNotEqual(m, None) + assertNotEqual(m, None) ## Running commands and checking results @@ -57,7 +57,7 @@ IMPLEMENTS THEN exit code is (\d+) h = yarnhelper.YarnHelper() code = get_next_match() - h.assertEqual(vars['exit'], int(code)) + assertEqual(vars['exit'], int(code)) IMPLEMENTS THEN standard output matches "(.+)" h = yarnhelper.YarnHelper() @@ -67,7 +67,7 @@ print 'pattern:', repr(pattern) print 'argv:', repr(vars['argv']) print 'stdout:', repr(stdout) - h.assertNotEqual(m, None) + assertNotEqual(m, None) IMPLEMENTS THEN standard error matches "(.+)" h = yarnhelper.YarnHelper() @@ -77,7 +77,7 @@ print 'pattern:', repr(pattern) print 'argv:', repr(vars['argv']) print 'stderr:', repr(stderr) - h.assertNotEqual(m, None) + assertNotEqual(m, None) # Mail handling tests @@ -129,7 +129,7 @@ print 'Subject:', msg['Subject'] got_it = got_it or (msg['Subject'] == subject) h.iterate_mails_in_imap_mailbox(address, user, password, match, False) - h.assertEqual(got_it, True) + assertTrue(got_it) ## Delete mails @@ -189,4 +189,4 @@ print 'Command:', cmd actual_status, msg = server.docmd(cmd) server.quit() - h.assertEqual(actual_status, wanted_status) + assertEqual(actual_status, wanted_status) diff --git a/yarnhelper.py b/yarnhelper.py index 5948664..9b47fde 100644 --- a/yarnhelper.py +++ b/yarnhelper.py @@ -26,16 +26,8 @@ import requests import yaml -datadir = os.environ.get('DATADIR', '.') -variables_filename = os.environ.get('VARIABLES', 'vars.yaml') - - class YarnHelper(object): - def __init__(self): - self._env = dict(os.environ) - self._filename = os.path.join(datadir, variables_filename) - def construct_aliased_http_request( self, address, method, url, data=None, headers=None): @@ -56,14 +48,6 @@ class YarnHelper(object): resp = s.send(r) return resp.status_code, resp.content - def assertEqual(self, a, b): - if a != b: - raise Error('assertion {!r} == {!r} failed'.format(a, b)) - - def assertNotEqual(self, a, b): - if a == b: - raise Error('assertion {!r} != {!r} failed'.format(a, b)) - def get_password_with_pass(self, pass_home, pass_name): # pragma: no cover p = subprocess.Popen( ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name], @@ -87,8 +71,3 @@ class YarnHelper(object): m.expunge() m.close() m.logout() - - -class Error(Exception): - - pass diff --git a/yarnhelper_tests.py b/yarnhelper_tests.py index 5e0f39a..40dc89e 100644 --- a/yarnhelper_tests.py +++ b/yarnhelper_tests.py @@ -31,24 +31,3 @@ class HttpTests(unittest.TestCase): r = h.construct_aliased_http_request(server, 'GET', url) self.assertEqual(r.url, 'http://new.example.com/path') self.assertEqual(r.headers['Host'], 'www.example.com') - - -class AssertionTests(unittest.TestCase): - - def test_assertEqual_asserts_equals_correctly(self): - h = yarnhelper.YarnHelper() - self.assertEqual(h.assertEqual(0, 0), None) - - def test_assertEqual_raises_error_for_nonequal_values(self): - h = yarnhelper.YarnHelper() - with self.assertRaises(yarnhelper.Error): - h.assertEqual(0, 1) - - def test_assertNotEqual_asserts_nonequal_correct(self): - h = yarnhelper.YarnHelper() - self.assertEqual(h.assertNotEqual(0, 1), None) - - def test_assertNotEqual_raises_error_for_equal_values(self): - h = yarnhelper.YarnHelper() - with self.assertRaises(yarnhelper.Error): - h.assertNotEqual(0, 0) -- cgit v1.2.1