# This defines the functions that implement each step. Functions # return either a saga.Success or a saga.Failure object. These are # subclasses of dict, and the runner generated by Saga will abort if a # step returns failure. Either dict may contain arbitrary fields. # # For simplicity, the runner will capture exceptions, and treats them # as failures with the exception stored within it. Also, it treats a # None return value as success with no keys. # # Values may be saved in named variables with the saga.set_variable # function and retrieved with the saga.get_variable function. It's an # error to retrieve an unset variable. import os import saga # This either returns None or raises an exception. def create_empty_git_repository(): subprocess.check-call(['git', 'init', '.'], stderr=subprocess.STDOUT) # This either returns None or raises an exception. def only_filename(filename): assert os.listdir('.') == [filename] # This run jt, with the --date= option that tells jt to pretend the # current date is as given. The runner sets PATH to have the source # directory of the project being tested. def run_jt(cmd): prefix = 'jt ' assert cmd.startswith(prefix) args = cmd[len(prefix:)] date = saga.get_variable('date') shellcmd = "jt --date={} {}".format(date, args) exitcode, output = subprocess.getstatusoutput( ['sh', '-c', shellcmd], stderr=subprocess.STDOUT) # We always return success, and expect the result to be checked by # a later step. return saga.Success(exitcode=exitcode, output=output) def exists(filename): assert os.path.exists(filename) def file_contains(filename, text): content = open(filename).read() assert text in content def shell_command_failed(captured_result=None): exitcode = captured['exitcode'] assert exitcode == 0 def stderr_contains(error, captured_result=None): stderr = captured_result['stderr'] assert error in stderr # These need to be passed to jt somehow, not sure how. That's not # important for now. def set_date(date): saga.save_variable('date', date)