diff options
-rwxr-xr-x | check | 10 | ||||
-rwxr-xr-x | cmdtest | 2 | ||||
-rw-r--r-- | cmdtest.1.in | 2 | ||||
-rw-r--r-- | fail-tests/fail.stdout-diff | 4 | ||||
-rw-r--r-- | setup.py | 18 | ||||
-rwxr-xr-x | yarn | 22 | ||||
-rw-r--r-- | yarnlib/mdparser.py | 11 |
7 files changed, 44 insertions, 25 deletions
@@ -1,5 +1,15 @@ #!/bin/sh +# +# Run unit and integration tests. set -eu +python3 -m unittest discover -p '*tests.py' + +./cmdtest echo-tests + +./cmdtest sort-tests + +./cmdtest fail-tests && echo "fail-tests did not fail!" && exit 1 + ./cmdtest yarn.tests @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2011 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify diff --git a/cmdtest.1.in b/cmdtest.1.in index c76f30c..9d13edd 100644 --- a/cmdtest.1.in +++ b/cmdtest.1.in @@ -182,7 +182,7 @@ Furthermore, the directory will contain the actual output files, and diffs from the expected files. If one of the actual output files is actually correct, -you can actualy rename it to be the expected file. +you can actually rename it to be the expected file. Actually, that's a very convenient way of creating the expected output files: you run the test, diff --git a/fail-tests/fail.stdout-diff b/fail-tests/fail.stdout-diff index 47ac588..5213747 100644 --- a/fail-tests/fail.stdout-diff +++ b/fail-tests/fail.stdout-diff @@ -1,4 +1,4 @@ ---- /dev/null 2017-04-20 17:06:09.455944599 +0300 -+++ fail-tests/fail.stdout-actual 2017-04-30 11:15:56.619905930 +0300 +--- /dev/null 2019-11-24 12:39:03.530622846 +0200 ++++ fail-tests/fail.stdout-actual 2019-11-28 10:36:18.968190788 +0200 @@ -0,0 +1 @@ +this is not empty output to make test fail @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2011 Lars Wirzenius <liw@liw.fi> # # This program is free software; you can redistribute it and/or modify @@ -43,13 +43,13 @@ class GenerateManpage(build): def run(self): build.run(self) - print 'building manpages' + print('building manpages') cmds = ['cmdtest'] if markdown_version: cmds.append('yarn') for x in cmds: with open('%s.1' % x, 'w') as f: - subprocess.check_call(['python', x, + subprocess.check_call(['python3', x, '--generate-manpage=%s.1.in' % x, '--output=%s.1' % x], stdout=f) @@ -76,7 +76,7 @@ class Check(Command): def run(self): if markdown_version: subprocess.check_call( - ['python', '-m', 'CoverageTestRunner', + ['python3', '-m', 'CoverageTestRunner', '--ignore-missing-from', 'without-tests']) if os.path.exists('.coverage'): os.remove('.coverage') @@ -110,4 +110,14 @@ setup(name='cmdtest', 'check': Check, 'clean': CleanMore, }, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'Operating System :: Unix', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Utilities', + ], ) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2013 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify @@ -116,8 +116,6 @@ class YarnRunner(cliapp.Application): self._write(sys.stderr, msg) def _write(self, output, msg): - if isinstance(msg, unicode): - msg = msg.encode(locale.getpreferredencoding()) output.write(msg) output.flush() @@ -332,7 +330,7 @@ class YarnRunner(cliapp.Application): started = time.time() self.info(0, 'Running scenario %s' % scenario.name) - self.ts['scenario_name'] = scenario.name.encode('utf-8') + self.ts['scenario_name'] = scenario.name self.ts.flush() self.scenarios_run += 1 @@ -450,7 +448,7 @@ class YarnRunner(cliapp.Application): self.info(1, 'Running step "%s %s"' % (step.what, step.text)) self.ts['current_step'] = step - self.ts['step_name'] = '%s %s' % (step.what, step.text.encode('utf8')) + self.ts['step_name'] = '%s %s' % (step.what, step.text) self.ts.flush() self.steps_run += 1 @@ -461,7 +459,7 @@ class YarnRunner(cliapp.Application): env['SRCDIR'] = os.getcwd() env['HOME'] = self.homedir(datadir) for i, match in enumerate(m.groups('')): - env['MATCH_%d' % (i+1)] = match.encode('utf-8') + env['MATCH_%d' % (i+1)] = match self.add_srcdir_to_pythonpath(env, env['SRCDIR']) if self.settings['cd-datadir']: @@ -487,11 +485,11 @@ class YarnRunner(cliapp.Application): logging.debug('Exit code: %d' % exit) if stdout: - logging.debug('Standard output:\n%s' % self.indent(stdout)) + logging.debug('Standard output:\n%s' % self.indent(stdout.decode())) else: logging.debug('Standard output: empty') if stderr: - logging.debug('Standard error:\n%s' % self.indent(stderr)) + logging.debug('Standard error:\n%s' % self.indent(stderr.decode())) else: logging.debug('Standard error: empty') @@ -500,9 +498,9 @@ class YarnRunner(cliapp.Application): self.error('step "%s %s" failed,' % (step.what, step.text)) self.error('with exit code %d:' % exit) self.error('Standard output from shell command:\n%s' % - self.indent(stdout)) + self.indent(stdout.decode())) self.error('Standard error from shell command:\n%s' % - self.indent(stderr)) + self.indent(stderr.decode())) self.remember_step_timing( '%s %s' % (step.what, step.text), time.time() - started) @@ -541,7 +539,9 @@ class YarnRunner(cliapp.Application): exit, out, err = cliapp.runcmd_unchecked( ['cp', '-ax', datadir, snapshot]) if exit != 0: - logging.warning('Snapshot copy failed:\n%s\n%s' % (out, err)) + logging.warning( + 'Snapshot copy failed:\n%s\n%s' % + (out.decode(), err.decode ())) def nice(self, name): # Quote a scenario or step name so it forms a nice filename. diff --git a/yarnlib/mdparser.py b/yarnlib/mdparser.py index 67851ec..9adf057 100644 --- a/yarnlib/mdparser.py +++ b/yarnlib/mdparser.py @@ -17,9 +17,9 @@ import logging -import HTMLParser +import html.parser import markdown -import StringIO +import io from markdown.treeprocessors import Treeprocessor @@ -41,7 +41,7 @@ class GatherCodeBlocks(Treeprocessor): self.blocks = blocks def run(self, root): - h = HTMLParser.HTMLParser() + h = html.parser.HTMLParser() for child in root.getchildren(): if child.tag == 'pre': code = child.find('code') @@ -68,13 +68,12 @@ class MarkdownParser(object): def parse_string(self, text): ext = ParseScenarioTestBlocks() - f = StringIO.StringIO() + f = io.StringIO() markdown.markdown(text, output=f, extensions=[ext]) self.blocks.extend(ext.blocks) return ext.blocks def parse_file(self, filename): # pragma: no cover with open(filename) as f: - binary = f.read() - text = binary.decode('utf-8') + text = f.read() return self.parse_string(text) |