From 3d999b0948b07b0ba2213f7904b241725e682c16 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 28 Nov 2019 10:11:12 +0200 Subject: Change: port to Python3 --- cmdtest | 2 +- setup.py | 8 ++++---- yarn | 22 +++++++++++----------- yarnlib/mdparser.py | 11 +++++------ 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cmdtest b/cmdtest index 1d60900..5a3f445 100755 --- a/cmdtest +++ b/cmdtest @@ -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/setup.py b/setup.py index 9ba00a2..1c11194 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2011 Lars Wirzenius # # 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') diff --git a/yarn b/yarn index d67c115..4b4db34 100755 --- a/yarn +++ b/yarn @@ -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) -- cgit v1.2.1 From 138d3d3d800f72ef24ed105cc6a2ec9f6476ba80 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 28 Nov 2019 10:05:36 +0200 Subject: Change: check to run more tests Thanks: Antonio Terceiro --- check | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/check b/check index 83fb46b..10dadd5 100755 --- a/check +++ b/check @@ -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 -- cgit v1.2.1 From bdf79d4ec3c53fa8515d6397b9531047ee5f1831 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 28 Nov 2019 10:17:14 +0200 Subject: Fix: type in manual page --- cmdtest.1.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, -- cgit v1.2.1 From 79d8518667def101a1a61135bc2c4609a219d0f9 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Mon, 25 Nov 2019 20:41:54 +0000 Subject: Add classifiers to setup.py --- setup.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup.py b/setup.py index 1c11194..2278ad8 100644 --- a/setup.py +++ b/setup.py @@ -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', + ], ) -- cgit v1.2.1 From 24960b9bd1e53e970b9a9796c268ce58cd5eff93 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 28 Nov 2019 10:36:48 +0200 Subject: Change: timestamp --- fail-tests/fail.stdout-diff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- cgit v1.2.1