From c3371ea883acd3a5ceb11b8d0daa47633fe28a20 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 13 Apr 2017 21:37:50 +0300 Subject: Convert to using yarnutils's Variables --- 900-implements.yarn | 93 +++++++++++++++++++++++++++-------------------------- lib.py | 4 +-- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/900-implements.yarn b/900-implements.yarn index 035c33a..4e64995 100644 --- a/900-implements.yarn +++ b/900-implements.yarn @@ -3,30 +3,29 @@ ## Server aliases IMPLEMENTS GIVEN server is also known as (\S+) - h = yarnhelper.YarnHelper() - h.set_variable('ALIAS', h.get_next_match()) + vars['ALIAS'] = get_next_match() ## HTTP requests IMPLEMENTS WHEN user fetches (\S+) h = yarnhelper.YarnHelper() address = os.environ['ADDRESS'] - url = h.get_next_match() + url = get_next_match() status, body = h.http_get(address, url) - h.set_variable('http_status', status) - h.set_variable('http_body', body) + vars['http_status'] = status + vars['http_body'] = body IMPLEMENTS THEN HTTP status is (\d+) h = yarnhelper.YarnHelper() - expected = h.get_variable('http_status') - actual = int(h.get_next_match()) + expected = vars['http_status'] + actual = int(get_next_match()) h.assertEqual(expected, actual) IMPLEMENTS THEN HTTP body matches "(.*)" h = yarnhelper.YarnHelper() - body = h.get_variable('http_body') + body = vars['http_body'] sys.stdout.write('Body:\n{}'.format(repr(body))) - pattern = h.get_next_match() + pattern = get_next_match() m = re.search(pattern, body) h.assertNotEqual(m, None) @@ -35,48 +34,48 @@ IMPLEMENTS WHEN user runs Gitano (.*) h = yarnhelper.YarnHelper() address = os.environ['ADDRESS'] - cmd = h.get_next_match() + cmd = get_next_match() argv = ['ssh', 'git@' + address] + cmd.split() exit, out, err = cliapp.runcmd_unchecked(argv) - h.set_variable('argv', argv) - h.set_variable('exit', int(exit)) - h.set_variable('stdout', out) - h.set_variable('stderr', err) + vars['argv'] = argv + vars['exit'] = int(exit) + vars['stdout'] = out + vars['stderr'] = err IMPLEMENTS WHEN user clones the (\S+) repository over git:// h = yarnhelper.YarnHelper() address = os.environ['ADDRESS'] - repo = h.get_next_match() + repo = get_next_match() url = 'git://{}/{}'.format(address, repo) argv = ['git', 'clone', url] exit, out, err = cliapp.runcmd_unchecked(argv, cwd=os.environ['DATADIR']) - h.set_variable('argv', argv) - h.set_variable('exit', int(exit)) - h.set_variable('stdout', out) - h.set_variable('stderr', err) + vars['argv'] = argv + vars['exit'] = int(exit) + vars['stdout'] = out + vars['stderr'] = err IMPLEMENTS THEN exit code is (\d+) h = yarnhelper.YarnHelper() - code = h.get_next_match() - h.assertEqual(h.get_variable('exit'), int(code)) + code = get_next_match() + h.assertEqual(vars['exit'], int(code)) IMPLEMENTS THEN standard output matches "(.+)" h = yarnhelper.YarnHelper() - pattern = h.get_next_match() - stdout = h.get_variable('stdout') + pattern = get_next_match() + stdout = vars['stdout'] m = re.search(pattern, stdout) print 'pattern:', repr(pattern) - print 'argv:', repr(h.get_variable('argv')) + print 'argv:', repr(vars['argv']) print 'stdout:', repr(stdout) h.assertNotEqual(m, None) IMPLEMENTS THEN standard error matches "(.+)" h = yarnhelper.YarnHelper() - pattern = h.get_next_match() - stderr = h.get_variable('stderr') + pattern = get_next_match() + stderr = vars['stderr'] m = re.search(pattern, stderr) print 'pattern:', repr(pattern) - print 'argv:', repr(h.get_variable('argv')) + print 'argv:', repr(vars['argv']) print 'stderr:', repr(stderr) h.assertNotEqual(m, None) @@ -86,11 +85,11 @@ IMPLEMENTS GIVEN large random number (\S+) h = yarnhelper.YarnHelper() - varname = h.get_next_match() + varname = get_next_match() mini = 2**32 maxi = 2**64 r = random.randint(mini, maxi) - h.set_variable(varname, str(r)) + vars[varname] = str(r) ## Send mail over SMTP+TLS @@ -98,9 +97,9 @@ IMPLEMENTS WHEN someone sends mail to (\S+) with subject \$(\S+) import smtplib h = yarnhelper.YarnHelper() - to_addr = h.get_next_match() - subject_key = h.get_next_match() - subject = h.get_variable(subject_key) + to_addr = get_next_match() + subject_key = get_next_match() + subject = vars[subject_key] address = os.environ['ADDRESS'] from_addr = 'someone@example.com' msg = 'From: {}\nTo: {}\nSubject: {}\n\nThis is the body\n'.format( @@ -116,9 +115,9 @@ IMPLEMENTS THEN mailbox of (\S+) has a mail with subject \$(\S+) h = yarnhelper.YarnHelper() - user = h.get_next_match() - subject_key = h.get_next_match() - subject = h.get_variable(subject_key) + user = get_next_match() + subject_key = get_next_match() + subject = vars[subject_key] print 'Wanted:', subject address = os.environ['ADDRESS'] pass_name = 'pieni.net/{}'.format(user) @@ -136,9 +135,9 @@ IMPLEMENTS THEN mails for (\S+) with subject \$(\S+) get deleted h = yarnhelper.YarnHelper() - user = h.get_next_match() - subject_key = h.get_next_match() - subject = h.get_variable(subject_key) + user = get_next_match() + subject_key = get_next_match() + subject = vars[subject_key] print 'Wanted:', subject address = os.environ['ADDRESS'] pass_name = 'pieni.net/{}'.format(user) @@ -154,22 +153,24 @@ IMPLEMENTS WHEN client SMTP authenticates as (\S+) h = yarnhelper.YarnHelper() - user = h.get_next_match() - h.set_variable('smtp_username', user) + user = get_next_match() + vars['smtp_username'] = user IMPLEMENTS WHEN client sends (.*) h = yarnhelper.YarnHelper() - command = h.get_next_match() - smtp_commands = h.get_variable('smtp_commands', []) + command = get_next_match() + smtp_commands = vars['smtp_commands'] + if smtp_commands is None: + smtp_commands = [] smtp_commands.append(command) - h.set_variable('smtp_commands', smtp_commands) + vars['smtp_commands'] = smtp_commands IMPLEMENTS THEN SMTP status code is (\d+) import smtplib h = yarnhelper.YarnHelper() - wanted_status = int(h.get_next_match()) - smtp_commands = h.get_variable('smtp_commands') - smtp_username = h.get_variable('smtp_username') + wanted_status = int(get_next_match()) + smtp_commands = vars['smtp_commands'] + smtp_username = vars['smtp_username'] if smtp_username is not None: pass_home = os.environ['PASS_HOME'] pass_user = 'pieni.net/{}'.format(smtp_username) diff --git a/lib.py b/lib.py index 45369e8..e0bc8cf 100644 --- a/lib.py +++ b/lib.py @@ -4,11 +4,11 @@ import re import sys import cliapp -import yarnutils +from yarnutils import * import yarnhelper srcdir = os.environ['SRCDIR'] datadir = os.environ['DATADIR'] -vars = yarnutils.Variables(datadir) +vars = Variables(datadir) -- cgit v1.2.1