mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
py: Reformat all Python files consistently
This commit is the unmodified results of running ``` black $(git ls-files '*.py') ``` with black version 19.10b0. See #2046. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
@@ -32,7 +32,7 @@ import unittest
|
||||
import taptestrunner
|
||||
|
||||
|
||||
Result = collections.namedtuple('Result', ('info', 'out', 'err', 'subs'))
|
||||
Result = collections.namedtuple("Result", ("info", "out", "err", "subs"))
|
||||
|
||||
|
||||
class TestGenmarshal(unittest.TestCase):
|
||||
@@ -47,22 +47,23 @@ class TestGenmarshal(unittest.TestCase):
|
||||
parsing and generation code out into a library and unit test that, and
|
||||
convert this test to just check command line behaviour.
|
||||
"""
|
||||
|
||||
# Track the cwd, we want to back out to that to clean up our tempdir
|
||||
cwd = ''
|
||||
cwd = ""
|
||||
|
||||
def setUp(self):
|
||||
self.timeout_seconds = 10 # seconds per test
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
self.cwd = os.getcwd()
|
||||
os.chdir(self.tmpdir.name)
|
||||
print('tmpdir:', self.tmpdir.name)
|
||||
if 'G_TEST_BUILDDIR' in os.environ:
|
||||
self.__genmarshal = \
|
||||
os.path.join(os.environ['G_TEST_BUILDDIR'], '..',
|
||||
'glib-genmarshal')
|
||||
print("tmpdir:", self.tmpdir.name)
|
||||
if "G_TEST_BUILDDIR" in os.environ:
|
||||
self.__genmarshal = os.path.join(
|
||||
os.environ["G_TEST_BUILDDIR"], "..", "glib-genmarshal"
|
||||
)
|
||||
else:
|
||||
self.__genmarshal = shutil.which('glib-genmarshal')
|
||||
print('genmarshal:', self.__genmarshal)
|
||||
self.__genmarshal = shutil.which("glib-genmarshal")
|
||||
print("genmarshal:", self.__genmarshal)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.cwd)
|
||||
@@ -73,48 +74,53 @@ class TestGenmarshal(unittest.TestCase):
|
||||
|
||||
# shebang lines are not supported on native
|
||||
# Windows consoles
|
||||
if os.name == 'nt':
|
||||
if os.name == "nt":
|
||||
argv.insert(0, sys.executable)
|
||||
|
||||
argv.extend(args)
|
||||
print('Running:', argv)
|
||||
print("Running:", argv)
|
||||
|
||||
env = os.environ.copy()
|
||||
env['LC_ALL'] = 'C.UTF-8'
|
||||
print('Environment:', env)
|
||||
env["LC_ALL"] = "C.UTF-8"
|
||||
print("Environment:", env)
|
||||
|
||||
# We want to ensure consistent line endings...
|
||||
info = subprocess.run(argv, timeout=self.timeout_seconds,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=env,
|
||||
universal_newlines=True)
|
||||
info = subprocess.run(
|
||||
argv,
|
||||
timeout=self.timeout_seconds,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=env,
|
||||
universal_newlines=True,
|
||||
)
|
||||
info.check_returncode()
|
||||
out = info.stdout.strip()
|
||||
err = info.stderr.strip()
|
||||
|
||||
# Known substitutions for standard boilerplate
|
||||
subs = {
|
||||
'standard_top_comment':
|
||||
'This file is generated by glib-genmarshal, do not modify '
|
||||
'it. This code is licensed under the same license as the '
|
||||
'containing project. Note that it links to GLib, so must '
|
||||
'comply with the LGPL linking clauses.',
|
||||
'standard_top_pragma': dedent(
|
||||
'''
|
||||
"standard_top_comment": "This file is generated by glib-genmarshal, do not modify "
|
||||
"it. This code is licensed under the same license as the "
|
||||
"containing project. Note that it links to GLib, so must "
|
||||
"comply with the LGPL linking clauses.",
|
||||
"standard_top_pragma": dedent(
|
||||
"""
|
||||
#ifndef __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__
|
||||
#define __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__
|
||||
''').strip(),
|
||||
'standard_bottom_pragma': dedent(
|
||||
'''
|
||||
"""
|
||||
).strip(),
|
||||
"standard_bottom_pragma": dedent(
|
||||
"""
|
||||
#endif /* __G_CCLOSURE_USER_MARSHAL_MARSHAL_H__ */
|
||||
''').strip(),
|
||||
'standard_includes': dedent(
|
||||
'''
|
||||
"""
|
||||
).strip(),
|
||||
"standard_includes": dedent(
|
||||
"""
|
||||
#include <glib-object.h>
|
||||
''').strip(),
|
||||
'standard_marshal_peek_defines': dedent(
|
||||
'''
|
||||
"""
|
||||
).strip(),
|
||||
"standard_marshal_peek_defines": dedent(
|
||||
"""
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
|
||||
#define g_marshal_value_peek_char(v) g_value_get_schar (v)
|
||||
@@ -160,54 +166,53 @@ class TestGenmarshal(unittest.TestCase):
|
||||
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
|
||||
#define g_marshal_value_peek_variant(v) (v)->data[0].v_pointer
|
||||
#endif /* !G_ENABLE_DEBUG */
|
||||
''').strip(),
|
||||
"""
|
||||
).strip(),
|
||||
}
|
||||
|
||||
result = Result(info, out, err, subs)
|
||||
|
||||
print('Output:', result.out)
|
||||
print("Output:", result.out)
|
||||
return result
|
||||
|
||||
def runGenmarshalWithList(self, list_contents, *args):
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
|
||||
suffix='.list',
|
||||
delete=False) as list_file:
|
||||
with tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, suffix=".list", delete=False
|
||||
) as list_file:
|
||||
# Write out the list.
|
||||
list_file.write(list_contents.encode('utf-8'))
|
||||
print(list_file.name + ':', list_contents)
|
||||
list_file.write(list_contents.encode("utf-8"))
|
||||
print(list_file.name + ":", list_contents)
|
||||
list_file.flush()
|
||||
|
||||
header_result = self.runGenmarshal(list_file.name,
|
||||
'--header', *args)
|
||||
body_result = self.runGenmarshal(list_file.name,
|
||||
'--body', *args)
|
||||
header_result = self.runGenmarshal(list_file.name, "--header", *args)
|
||||
body_result = self.runGenmarshal(list_file.name, "--body", *args)
|
||||
|
||||
header_result.subs['list_path'] = list_file.name
|
||||
body_result.subs['list_path'] = list_file.name
|
||||
header_result.subs["list_path"] = list_file.name
|
||||
body_result.subs["list_path"] = list_file.name
|
||||
|
||||
return (header_result, body_result)
|
||||
|
||||
def test_help(self):
|
||||
"""Test the --help argument."""
|
||||
result = self.runGenmarshal('--help')
|
||||
self.assertIn('usage: glib-genmarshal', result.out)
|
||||
result = self.runGenmarshal("--help")
|
||||
self.assertIn("usage: glib-genmarshal", result.out)
|
||||
|
||||
def test_no_args(self):
|
||||
"""Test running with no arguments at all."""
|
||||
result = self.runGenmarshal()
|
||||
self.assertEqual('', result.err)
|
||||
self.assertEqual('', result.out)
|
||||
self.assertEqual("", result.err)
|
||||
self.assertEqual("", result.out)
|
||||
|
||||
def test_empty_list(self):
|
||||
"""Test running with an empty list."""
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('', '--quiet')
|
||||
(header_result, body_result) = self.runGenmarshalWithList("", "--quiet")
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -219,28 +224,39 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_includes}
|
||||
|
||||
{standard_marshal_peek_defines}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
def test_void_boolean(self):
|
||||
"""Test running with a basic VOID:BOOLEAN list."""
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('VOID:BOOLEAN', '--quiet')
|
||||
(header_result, body_result) = self.runGenmarshalWithList(
|
||||
"VOID:BOOLEAN", "--quiet"
|
||||
)
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -255,28 +271,39 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_includes}
|
||||
|
||||
{standard_marshal_peek_defines}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
def test_void_boolean_int64(self):
|
||||
"""Test running with a non-trivial VOID:BOOLEAN,INT64 list."""
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('VOID:BOOLEAN,INT64', '--quiet')
|
||||
(header_result, body_result) = self.runGenmarshalWithList(
|
||||
"VOID:BOOLEAN,INT64", "--quiet"
|
||||
)
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -297,11 +324,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_includes}
|
||||
|
||||
@@ -343,8 +375,12 @@ class TestGenmarshal(unittest.TestCase):
|
||||
g_marshal_value_peek_int64 (param_values + 2),
|
||||
data2);
|
||||
}}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
def test_void_variant_nostdinc_valist_marshaller(self):
|
||||
"""Test running with a basic VOID:VARIANT list, but without the
|
||||
@@ -353,15 +389,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
|
||||
See issue #1793.
|
||||
"""
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('VOID:VARIANT', '--quiet', '--nostdinc',
|
||||
'--valist-marshaller')
|
||||
(header_result, body_result) = self.runGenmarshalWithList(
|
||||
"VOID:VARIANT", "--quiet", "--nostdinc", "--valist-marshaller"
|
||||
)
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -388,11 +425,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_marshal_peek_defines}
|
||||
|
||||
@@ -474,8 +516,12 @@ class TestGenmarshal(unittest.TestCase):
|
||||
if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
|
||||
g_variant_unref (arg0);
|
||||
}}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
def test_void_string_nostdinc(self):
|
||||
"""Test running with a basic VOID:STRING list, but without the
|
||||
@@ -485,15 +531,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
|
||||
See issue #1792.
|
||||
"""
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('VOID:STRING', '--quiet', '--nostdinc',
|
||||
'--valist-marshaller')
|
||||
(header_result, body_result) = self.runGenmarshalWithList(
|
||||
"VOID:STRING", "--quiet", "--nostdinc", "--valist-marshaller"
|
||||
)
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -520,11 +567,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_marshal_peek_defines}
|
||||
|
||||
@@ -606,8 +658,12 @@ class TestGenmarshal(unittest.TestCase):
|
||||
if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
|
||||
g_free (arg0);
|
||||
}}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
def test_void_param_nostdinc(self):
|
||||
"""Test running with a basic VOID:PARAM list, but without the
|
||||
@@ -618,15 +674,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
See issue #1792.
|
||||
"""
|
||||
self.maxDiff = None # TODO
|
||||
(header_result, body_result) = \
|
||||
self.runGenmarshalWithList('VOID:PARAM', '--quiet', '--nostdinc',
|
||||
'--valist-marshaller')
|
||||
(header_result, body_result) = self.runGenmarshalWithList(
|
||||
"VOID:PARAM", "--quiet", "--nostdinc", "--valist-marshaller"
|
||||
)
|
||||
|
||||
self.assertEqual('', header_result.err)
|
||||
self.assertEqual('', body_result.err)
|
||||
self.assertEqual("", header_result.err)
|
||||
self.assertEqual("", body_result.err)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_top_pragma}
|
||||
|
||||
@@ -653,11 +710,16 @@ class TestGenmarshal(unittest.TestCase):
|
||||
G_END_DECLS
|
||||
|
||||
{standard_bottom_pragma}
|
||||
''').strip().format(**header_result.subs),
|
||||
header_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**header_result.subs),
|
||||
header_result.out.strip(),
|
||||
)
|
||||
|
||||
self.assertEqual(dedent(
|
||||
'''
|
||||
self.assertEqual(
|
||||
dedent(
|
||||
"""
|
||||
/* {standard_top_comment} */
|
||||
{standard_marshal_peek_defines}
|
||||
|
||||
@@ -739,9 +801,13 @@ class TestGenmarshal(unittest.TestCase):
|
||||
if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
|
||||
g_param_spec_unref (arg0);
|
||||
}}
|
||||
''').strip().format(**body_result.subs),
|
||||
body_result.out.strip())
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(**body_result.subs),
|
||||
body_result.out.strip(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
||||
|
@@ -32,7 +32,7 @@ import unittest
|
||||
import taptestrunner
|
||||
|
||||
|
||||
Result = collections.namedtuple('Result', ('info', 'out', 'err', 'subs'))
|
||||
Result = collections.namedtuple("Result", ("info", "out", "err", "subs"))
|
||||
|
||||
|
||||
class TestMkenums(unittest.TestCase):
|
||||
@@ -47,8 +47,9 @@ class TestMkenums(unittest.TestCase):
|
||||
parsing and generation code out into a library and unit test that, and
|
||||
convert this test to just check command line behaviour.
|
||||
"""
|
||||
|
||||
# Track the cwd, we want to back out to that to clean up our tempdir
|
||||
cwd = ''
|
||||
cwd = ""
|
||||
rspfile = False
|
||||
|
||||
def setUp(self):
|
||||
@@ -56,14 +57,14 @@ class TestMkenums(unittest.TestCase):
|
||||
self.tmpdir = tempfile.TemporaryDirectory()
|
||||
self.cwd = os.getcwd()
|
||||
os.chdir(self.tmpdir.name)
|
||||
print('tmpdir:', self.tmpdir.name)
|
||||
if 'G_TEST_BUILDDIR' in os.environ:
|
||||
self.__mkenums = \
|
||||
os.path.join(os.environ['G_TEST_BUILDDIR'], '..',
|
||||
'glib-mkenums')
|
||||
print("tmpdir:", self.tmpdir.name)
|
||||
if "G_TEST_BUILDDIR" in os.environ:
|
||||
self.__mkenums = os.path.join(
|
||||
os.environ["G_TEST_BUILDDIR"], "..", "glib-mkenums"
|
||||
)
|
||||
else:
|
||||
self.__mkenums = shutil.which('glib-mkenums')
|
||||
print('rspfile: {}, mkenums:'.format(self.rspfile), self.__mkenums)
|
||||
self.__mkenums = shutil.which("glib-mkenums")
|
||||
print("rspfile: {}, mkenums:".format(self.rspfile), self.__mkenums)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.cwd)
|
||||
@@ -71,10 +72,12 @@ class TestMkenums(unittest.TestCase):
|
||||
|
||||
def _write_rspfile(self, argv):
|
||||
import shlex
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name, mode='w',
|
||||
delete=False) as f:
|
||||
contents = ' '.join([shlex.quote(arg) for arg in argv])
|
||||
print('Response file contains:', contents)
|
||||
|
||||
with tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, mode="w", delete=False
|
||||
) as f:
|
||||
contents = " ".join([shlex.quote(arg) for arg in argv])
|
||||
print("Response file contains:", contents)
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
return f.name
|
||||
@@ -82,60 +85,62 @@ class TestMkenums(unittest.TestCase):
|
||||
def runMkenums(self, *args):
|
||||
if self.rspfile:
|
||||
rspfile = self._write_rspfile(args)
|
||||
args = ['@' + rspfile]
|
||||
args = ["@" + rspfile]
|
||||
argv = [self.__mkenums]
|
||||
|
||||
# shebang lines are not supported on native
|
||||
# Windows consoles
|
||||
if os.name == 'nt':
|
||||
if os.name == "nt":
|
||||
argv.insert(0, sys.executable)
|
||||
|
||||
argv.extend(args)
|
||||
print('Running:', argv)
|
||||
print("Running:", argv)
|
||||
|
||||
env = os.environ.copy()
|
||||
env['LC_ALL'] = 'C.UTF-8'
|
||||
print('Environment:', env)
|
||||
env["LC_ALL"] = "C.UTF-8"
|
||||
print("Environment:", env)
|
||||
|
||||
# We want to ensure consistent line endings...
|
||||
info = subprocess.run(argv, timeout=self.timeout_seconds,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=env,
|
||||
universal_newlines=True)
|
||||
info = subprocess.run(
|
||||
argv,
|
||||
timeout=self.timeout_seconds,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=env,
|
||||
universal_newlines=True,
|
||||
)
|
||||
info.check_returncode()
|
||||
out = info.stdout.strip()
|
||||
err = info.stderr.strip()
|
||||
|
||||
# Known substitutions for standard boilerplate
|
||||
subs = {
|
||||
'standard_top_comment':
|
||||
'This file is generated by glib-mkenums, do not modify '
|
||||
'it. This code is licensed under the same license as the '
|
||||
'containing project. Note that it links to GLib, so must '
|
||||
'comply with the LGPL linking clauses.',
|
||||
'standard_bottom_comment': 'Generated data ends here'
|
||||
"standard_top_comment": "This file is generated by glib-mkenums, do not modify "
|
||||
"it. This code is licensed under the same license as the "
|
||||
"containing project. Note that it links to GLib, so must "
|
||||
"comply with the LGPL linking clauses.",
|
||||
"standard_bottom_comment": "Generated data ends here",
|
||||
}
|
||||
|
||||
result = Result(info, out, err, subs)
|
||||
|
||||
print('Output:', result.out)
|
||||
print("Output:", result.out)
|
||||
return result
|
||||
|
||||
def runMkenumsWithTemplate(self, template_contents, *args):
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
|
||||
suffix='.template',
|
||||
delete=False) as template_file:
|
||||
with tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, suffix=".template", delete=False
|
||||
) as template_file:
|
||||
# Write out the template.
|
||||
template_file.write(template_contents.encode('utf-8'))
|
||||
print(template_file.name + ':', template_contents)
|
||||
template_file.write(template_contents.encode("utf-8"))
|
||||
print(template_file.name + ":", template_contents)
|
||||
template_file.flush()
|
||||
|
||||
return self.runMkenums('--template', template_file.name, *args)
|
||||
return self.runMkenums("--template", template_file.name, *args)
|
||||
|
||||
def runMkenumsWithAllSubstitutions(self, *args):
|
||||
'''Run glib-mkenums with a template which outputs all substitutions.'''
|
||||
template_contents = '''
|
||||
"""Run glib-mkenums with a template which outputs all substitutions."""
|
||||
template_contents = """
|
||||
/*** BEGIN file-header ***/
|
||||
file-header
|
||||
/*** END file-header ***/
|
||||
@@ -203,51 +208,66 @@ comment: @comment@
|
||||
/*** BEGIN file-tail ***/
|
||||
file-tail
|
||||
/*** END file-tail ***/
|
||||
'''
|
||||
"""
|
||||
return self.runMkenumsWithTemplate(template_contents, *args)
|
||||
|
||||
def runMkenumsWithHeader(self, h_contents, encoding='utf-8'):
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
|
||||
suffix='.h',
|
||||
delete=False) as h_file:
|
||||
def runMkenumsWithHeader(self, h_contents, encoding="utf-8"):
|
||||
with tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, suffix=".h", delete=False
|
||||
) as h_file:
|
||||
# Write out the header to be scanned.
|
||||
h_file.write(h_contents.encode(encoding))
|
||||
print(h_file.name + ':', h_contents)
|
||||
print(h_file.name + ":", h_contents)
|
||||
h_file.flush()
|
||||
|
||||
# Run glib-mkenums with a template which outputs all substitutions.
|
||||
result = self.runMkenumsWithAllSubstitutions(h_file.name)
|
||||
|
||||
# Known substitutions for generated filenames.
|
||||
result.subs.update({
|
||||
'filename': h_file.name,
|
||||
'basename': os.path.basename(h_file.name),
|
||||
})
|
||||
result.subs.update(
|
||||
{"filename": h_file.name, "basename": os.path.basename(h_file.name),}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def assertSingleEnum(self, result, enum_name_camel, enum_name_lower,
|
||||
enum_name_upper, enum_name_short, enum_prefix,
|
||||
enum_since, type_lower, type_camel, type_upper,
|
||||
value_name, value_nick, value_num):
|
||||
def assertSingleEnum(
|
||||
self,
|
||||
result,
|
||||
enum_name_camel,
|
||||
enum_name_lower,
|
||||
enum_name_upper,
|
||||
enum_name_short,
|
||||
enum_prefix,
|
||||
enum_since,
|
||||
type_lower,
|
||||
type_camel,
|
||||
type_upper,
|
||||
value_name,
|
||||
value_nick,
|
||||
value_num,
|
||||
):
|
||||
"""Assert that out (from runMkenumsWithHeader()) contains a single
|
||||
enum and value matching the given arguments."""
|
||||
subs = dict({
|
||||
'enum_name_camel': enum_name_camel,
|
||||
'enum_name_lower': enum_name_lower,
|
||||
'enum_name_upper': enum_name_upper,
|
||||
'enum_name_short': enum_name_short,
|
||||
'enum_prefix': enum_prefix,
|
||||
'enum_since': enum_since,
|
||||
'type_lower': type_lower,
|
||||
'type_camel': type_camel,
|
||||
'type_upper': type_upper,
|
||||
'value_name': value_name,
|
||||
'value_nick': value_nick,
|
||||
'value_num': value_num,
|
||||
}, **result.subs)
|
||||
subs = dict(
|
||||
{
|
||||
"enum_name_camel": enum_name_camel,
|
||||
"enum_name_lower": enum_name_lower,
|
||||
"enum_name_upper": enum_name_upper,
|
||||
"enum_name_short": enum_name_short,
|
||||
"enum_prefix": enum_prefix,
|
||||
"enum_since": enum_since,
|
||||
"type_lower": type_lower,
|
||||
"type_camel": type_camel,
|
||||
"type_upper": type_upper,
|
||||
"value_name": value_name,
|
||||
"value_nick": value_nick,
|
||||
"value_num": value_num,
|
||||
},
|
||||
**result.subs
|
||||
)
|
||||
|
||||
self.assertEqual('''
|
||||
self.assertEqual(
|
||||
"""
|
||||
comment
|
||||
comment: {standard_top_comment}
|
||||
|
||||
@@ -297,38 +317,51 @@ file-tail
|
||||
|
||||
comment
|
||||
comment: {standard_bottom_comment}
|
||||
'''.format(**subs).strip(), result.out)
|
||||
""".format(
|
||||
**subs
|
||||
).strip(),
|
||||
result.out,
|
||||
)
|
||||
|
||||
def test_help(self):
|
||||
"""Test the --help argument."""
|
||||
result = self.runMkenums('--help')
|
||||
self.assertIn('usage: glib-mkenums', result.out)
|
||||
result = self.runMkenums("--help")
|
||||
self.assertIn("usage: glib-mkenums", result.out)
|
||||
|
||||
def test_no_args(self):
|
||||
"""Test running with no arguments at all."""
|
||||
result = self.runMkenums()
|
||||
self.assertEqual('', result.err)
|
||||
self.assertEqual('''/* {standard_top_comment} */
|
||||
self.assertEqual("", result.err)
|
||||
self.assertEqual(
|
||||
"""/* {standard_top_comment} */
|
||||
|
||||
|
||||
/* {standard_bottom_comment} */'''.format(**result.subs),
|
||||
result.out.strip())
|
||||
/* {standard_bottom_comment} */""".format(
|
||||
**result.subs
|
||||
),
|
||||
result.out.strip(),
|
||||
)
|
||||
|
||||
def test_empty_template(self):
|
||||
"""Test running with an empty template and no header files."""
|
||||
result = self.runMkenumsWithTemplate('')
|
||||
self.assertEqual('', result.err)
|
||||
self.assertEqual('''/* {standard_top_comment} */
|
||||
result = self.runMkenumsWithTemplate("")
|
||||
self.assertEqual("", result.err)
|
||||
self.assertEqual(
|
||||
"""/* {standard_top_comment} */
|
||||
|
||||
|
||||
/* {standard_bottom_comment} */'''.format(**result.subs),
|
||||
result.out.strip())
|
||||
/* {standard_bottom_comment} */""".format(
|
||||
**result.subs
|
||||
),
|
||||
result.out.strip(),
|
||||
)
|
||||
|
||||
def test_no_headers(self):
|
||||
"""Test running with a complete template, but no header files."""
|
||||
result = self.runMkenumsWithAllSubstitutions()
|
||||
self.assertEqual('', result.err)
|
||||
self.assertEqual('''
|
||||
self.assertEqual("", result.err)
|
||||
self.assertEqual(
|
||||
"""
|
||||
comment
|
||||
comment: {standard_top_comment}
|
||||
|
||||
@@ -338,13 +371,18 @@ file-tail
|
||||
|
||||
comment
|
||||
comment: {standard_bottom_comment}
|
||||
'''.format(**result.subs).strip(), result.out)
|
||||
""".format(
|
||||
**result.subs
|
||||
).strip(),
|
||||
result.out,
|
||||
)
|
||||
|
||||
def test_empty_header(self):
|
||||
"""Test an empty header."""
|
||||
result = self.runMkenumsWithHeader('')
|
||||
self.assertEqual('', result.err)
|
||||
self.assertEqual('''
|
||||
result = self.runMkenumsWithHeader("")
|
||||
self.assertEqual("", result.err)
|
||||
self.assertEqual(
|
||||
"""
|
||||
comment
|
||||
comment: {standard_top_comment}
|
||||
|
||||
@@ -354,94 +392,134 @@ file-tail
|
||||
|
||||
comment
|
||||
comment: {standard_bottom_comment}
|
||||
'''.format(**result.subs).strip(), result.out)
|
||||
""".format(
|
||||
**result.subs
|
||||
).strip(),
|
||||
result.out,
|
||||
)
|
||||
|
||||
def test_enum_name(self):
|
||||
"""Test typedefs with an enum and a typedef name. Bug #794506."""
|
||||
h_contents = '''
|
||||
h_contents = """
|
||||
typedef enum _SomeEnumIdentifier {
|
||||
ENUM_VALUE
|
||||
} SomeEnumIdentifier;
|
||||
'''
|
||||
"""
|
||||
result = self.runMkenumsWithHeader(h_contents)
|
||||
self.assertEqual('', result.err)
|
||||
self.assertSingleEnum(result, 'SomeEnumIdentifier',
|
||||
'some_enum_identifier', 'SOME_ENUM_IDENTIFIER',
|
||||
'ENUM_IDENTIFIER', 'SOME', '', 'enum', 'Enum',
|
||||
'ENUM', 'ENUM_VALUE', 'value', '0')
|
||||
self.assertEqual("", result.err)
|
||||
self.assertSingleEnum(
|
||||
result,
|
||||
"SomeEnumIdentifier",
|
||||
"some_enum_identifier",
|
||||
"SOME_ENUM_IDENTIFIER",
|
||||
"ENUM_IDENTIFIER",
|
||||
"SOME",
|
||||
"",
|
||||
"enum",
|
||||
"Enum",
|
||||
"ENUM",
|
||||
"ENUM_VALUE",
|
||||
"value",
|
||||
"0",
|
||||
)
|
||||
|
||||
def test_non_utf8_encoding(self):
|
||||
"""Test source files with non-UTF-8 encoding. Bug #785113."""
|
||||
h_contents = '''
|
||||
h_contents = """
|
||||
/* Copyright © La Peña */
|
||||
typedef enum {
|
||||
ENUM_VALUE
|
||||
} SomeEnumIdentifier;
|
||||
'''
|
||||
result = self.runMkenumsWithHeader(h_contents, encoding='iso-8859-1')
|
||||
self.assertIn('WARNING: UnicodeWarning: ', result.err)
|
||||
self.assertSingleEnum(result, 'SomeEnumIdentifier',
|
||||
'some_enum_identifier', 'SOME_ENUM_IDENTIFIER',
|
||||
'ENUM_IDENTIFIER', 'SOME', '', 'enum', 'Enum',
|
||||
'ENUM', 'ENUM_VALUE', 'value', '0')
|
||||
"""
|
||||
result = self.runMkenumsWithHeader(h_contents, encoding="iso-8859-1")
|
||||
self.assertIn("WARNING: UnicodeWarning: ", result.err)
|
||||
self.assertSingleEnum(
|
||||
result,
|
||||
"SomeEnumIdentifier",
|
||||
"some_enum_identifier",
|
||||
"SOME_ENUM_IDENTIFIER",
|
||||
"ENUM_IDENTIFIER",
|
||||
"SOME",
|
||||
"",
|
||||
"enum",
|
||||
"Enum",
|
||||
"ENUM",
|
||||
"ENUM_VALUE",
|
||||
"value",
|
||||
"0",
|
||||
)
|
||||
|
||||
def test_reproducible(self):
|
||||
"""Test builds are reproducible regardless of file ordering.
|
||||
Bug #691436."""
|
||||
template_contents = 'template'
|
||||
template_contents = "template"
|
||||
|
||||
h_contents1 = '''
|
||||
h_contents1 = """
|
||||
typedef enum {
|
||||
FIRST,
|
||||
} Header1;
|
||||
'''
|
||||
"""
|
||||
|
||||
h_contents2 = '''
|
||||
h_contents2 = """
|
||||
typedef enum {
|
||||
SECOND,
|
||||
} Header2;
|
||||
'''
|
||||
"""
|
||||
|
||||
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
|
||||
suffix='1.h', delete=False) as h_file1, \
|
||||
tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
|
||||
suffix='2.h', delete=False) as h_file2:
|
||||
with tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, suffix="1.h", delete=False
|
||||
) as h_file1, tempfile.NamedTemporaryFile(
|
||||
dir=self.tmpdir.name, suffix="2.h", delete=False
|
||||
) as h_file2:
|
||||
# Write out the headers.
|
||||
h_file1.write(h_contents1.encode('utf-8'))
|
||||
h_file2.write(h_contents2.encode('utf-8'))
|
||||
h_file1.write(h_contents1.encode("utf-8"))
|
||||
h_file2.write(h_contents2.encode("utf-8"))
|
||||
|
||||
h_file1.flush()
|
||||
h_file2.flush()
|
||||
|
||||
# Run glib-mkenums with the headers in one order, and then again
|
||||
# in another order.
|
||||
result1 = self.runMkenumsWithTemplate(template_contents,
|
||||
h_file1.name, h_file2.name)
|
||||
self.assertEqual('', result1.err)
|
||||
result1 = self.runMkenumsWithTemplate(
|
||||
template_contents, h_file1.name, h_file2.name
|
||||
)
|
||||
self.assertEqual("", result1.err)
|
||||
|
||||
result2 = self.runMkenumsWithTemplate(template_contents,
|
||||
h_file2.name, h_file1.name)
|
||||
self.assertEqual('', result2.err)
|
||||
result2 = self.runMkenumsWithTemplate(
|
||||
template_contents, h_file2.name, h_file1.name
|
||||
)
|
||||
self.assertEqual("", result2.err)
|
||||
|
||||
# The output should be the same.
|
||||
self.assertEqual(result1.out, result2.out)
|
||||
|
||||
def test_no_nick(self):
|
||||
"""Test trigraphs with a desc but no nick. Issue #1360."""
|
||||
h_contents = '''
|
||||
h_contents = """
|
||||
typedef enum {
|
||||
GEGL_SAMPLER_NEAREST = 0, /*< desc="nearest" >*/
|
||||
} GeglSamplerType;
|
||||
'''
|
||||
"""
|
||||
result = self.runMkenumsWithHeader(h_contents)
|
||||
self.assertEqual('', result.err)
|
||||
self.assertSingleEnum(result, 'GeglSamplerType',
|
||||
'gegl_sampler_type', 'GEGL_SAMPLER_TYPE',
|
||||
'SAMPLER_TYPE', 'GEGL', '', 'enum', 'Enum',
|
||||
'ENUM', 'GEGL_SAMPLER_NEAREST', 'nearest', '0')
|
||||
self.assertEqual("", result.err)
|
||||
self.assertSingleEnum(
|
||||
result,
|
||||
"GeglSamplerType",
|
||||
"gegl_sampler_type",
|
||||
"GEGL_SAMPLER_TYPE",
|
||||
"SAMPLER_TYPE",
|
||||
"GEGL",
|
||||
"",
|
||||
"enum",
|
||||
"Enum",
|
||||
"ENUM",
|
||||
"GEGL_SAMPLER_NEAREST",
|
||||
"nearest",
|
||||
"0",
|
||||
)
|
||||
|
||||
def test_filename_basename_in_fhead_ftail(self):
|
||||
template_contents = '''
|
||||
template_contents = """
|
||||
/*** BEGIN file-header ***/
|
||||
file-header
|
||||
filename: @filename@
|
||||
@@ -457,18 +535,21 @@ comment: @comment@
|
||||
file-tail
|
||||
filename: @filename@
|
||||
basename: @basename@
|
||||
/*** END file-tail ***/'''
|
||||
/*** END file-tail ***/"""
|
||||
result = self.runMkenumsWithTemplate(template_contents)
|
||||
self.assertEqual(
|
||||
textwrap.dedent(
|
||||
'''
|
||||
"""
|
||||
WARNING: @filename@ used in file-header section.
|
||||
WARNING: @basename@ used in file-header section.
|
||||
WARNING: @filename@ used in file-tail section.
|
||||
WARNING: @basename@ used in file-tail section.
|
||||
''').strip(),
|
||||
result.err)
|
||||
self.assertEqual('''
|
||||
"""
|
||||
).strip(),
|
||||
result.err,
|
||||
)
|
||||
self.assertEqual(
|
||||
"""
|
||||
comment
|
||||
comment: {standard_top_comment}
|
||||
|
||||
@@ -482,27 +563,44 @@ basename: @basename@
|
||||
|
||||
comment
|
||||
comment: {standard_bottom_comment}
|
||||
'''.format(**result.subs).strip(), result.out)
|
||||
""".format(
|
||||
**result.subs
|
||||
).strip(),
|
||||
result.out,
|
||||
)
|
||||
|
||||
def test_since(self):
|
||||
"""Test user-provided 'since' version handling
|
||||
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1492"""
|
||||
h_contents = '''
|
||||
h_contents = """
|
||||
typedef enum { /*< since=1.0 >*/
|
||||
QMI_WMS_MESSAGE_PROTOCOL_CDMA = 0,
|
||||
} QmiWmsMessageProtocol;
|
||||
'''
|
||||
"""
|
||||
result = self.runMkenumsWithHeader(h_contents)
|
||||
self.assertEqual('', result.err)
|
||||
self.assertSingleEnum(result, 'QmiWmsMessageProtocol',
|
||||
'qmi_wms_message_protocol', 'QMI_WMS_MESSAGE_PROTOCOL',
|
||||
'WMS_MESSAGE_PROTOCOL', 'QMI', '1.0', 'enum', 'Enum',
|
||||
'ENUM', 'QMI_WMS_MESSAGE_PROTOCOL_CDMA', 'cdma', '0')
|
||||
self.assertEqual("", result.err)
|
||||
self.assertSingleEnum(
|
||||
result,
|
||||
"QmiWmsMessageProtocol",
|
||||
"qmi_wms_message_protocol",
|
||||
"QMI_WMS_MESSAGE_PROTOCOL",
|
||||
"WMS_MESSAGE_PROTOCOL",
|
||||
"QMI",
|
||||
"1.0",
|
||||
"enum",
|
||||
"Enum",
|
||||
"ENUM",
|
||||
"QMI_WMS_MESSAGE_PROTOCOL_CDMA",
|
||||
"cdma",
|
||||
"0",
|
||||
)
|
||||
|
||||
|
||||
class TestRspMkenums(TestMkenums):
|
||||
'''Run all tests again in @rspfile mode'''
|
||||
"""Run all tests again in @rspfile mode"""
|
||||
|
||||
rspfile = True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
||||
|
@@ -31,146 +31,155 @@ import base64
|
||||
from io import StringIO
|
||||
|
||||
# Log modes
|
||||
class LogMode(object) :
|
||||
LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4)
|
||||
class LogMode(object):
|
||||
LogToError, LogToDiagnostics, LogToYAML, LogToAttachment = range(4)
|
||||
|
||||
|
||||
class TAPTestResult(unittest.TestResult):
|
||||
def __init__(self, output_stream, error_stream, message_log, test_output_log):
|
||||
super(TAPTestResult, self).__init__(self, output_stream)
|
||||
self.output_stream = output_stream
|
||||
self.error_stream = error_stream
|
||||
self.orig_stdout = None
|
||||
self.orig_stderr = None
|
||||
self.message = None
|
||||
self.test_output = None
|
||||
self.message_log = message_log
|
||||
self.test_output_log = test_output_log
|
||||
self.output_stream.write("TAP version 13\n")
|
||||
self._set_streams()
|
||||
def __init__(self, output_stream, error_stream, message_log, test_output_log):
|
||||
super(TAPTestResult, self).__init__(self, output_stream)
|
||||
self.output_stream = output_stream
|
||||
self.error_stream = error_stream
|
||||
self.orig_stdout = None
|
||||
self.orig_stderr = None
|
||||
self.message = None
|
||||
self.test_output = None
|
||||
self.message_log = message_log
|
||||
self.test_output_log = test_output_log
|
||||
self.output_stream.write("TAP version 13\n")
|
||||
self._set_streams()
|
||||
|
||||
def printErrors(self):
|
||||
self.print_raw("1..%d\n" % self.testsRun)
|
||||
self._reset_streams()
|
||||
def printErrors(self):
|
||||
self.print_raw("1..%d\n" % self.testsRun)
|
||||
self._reset_streams()
|
||||
|
||||
def _set_streams(self):
|
||||
self.orig_stdout = sys.stdout
|
||||
self.orig_stderr = sys.stderr
|
||||
if self.message_log == LogMode.LogToError:
|
||||
self.message = self.error_stream
|
||||
else:
|
||||
self.message = StringIO()
|
||||
if self.test_output_log == LogMode.LogToError:
|
||||
self.test_output = self.error_stream
|
||||
else:
|
||||
self.test_output = StringIO()
|
||||
def _set_streams(self):
|
||||
self.orig_stdout = sys.stdout
|
||||
self.orig_stderr = sys.stderr
|
||||
if self.message_log == LogMode.LogToError:
|
||||
self.message = self.error_stream
|
||||
else:
|
||||
self.message = StringIO()
|
||||
if self.test_output_log == LogMode.LogToError:
|
||||
self.test_output = self.error_stream
|
||||
else:
|
||||
self.test_output = StringIO()
|
||||
|
||||
if self.message_log == self.test_output_log:
|
||||
self.test_output = self.message
|
||||
sys.stdout = sys.stderr = self.test_output
|
||||
if self.message_log == self.test_output_log:
|
||||
self.test_output = self.message
|
||||
sys.stdout = sys.stderr = self.test_output
|
||||
|
||||
def _reset_streams(self):
|
||||
sys.stdout = self.orig_stdout
|
||||
sys.stderr = self.orig_stderr
|
||||
def _reset_streams(self):
|
||||
sys.stdout = self.orig_stdout
|
||||
sys.stderr = self.orig_stderr
|
||||
|
||||
def print_raw(self, text):
|
||||
self.output_stream.write(text)
|
||||
self.output_stream.flush()
|
||||
|
||||
def print_raw(self, text):
|
||||
self.output_stream.write(text)
|
||||
self.output_stream.flush()
|
||||
def print_result(self, result, test, directive=None):
|
||||
self.output_stream.write("%s %d %s" % (result, self.testsRun, test.id()))
|
||||
if directive:
|
||||
self.output_stream.write(" # " + directive)
|
||||
self.output_stream.write("\n")
|
||||
self.output_stream.flush()
|
||||
|
||||
def print_result(self, result, test, directive = None):
|
||||
self.output_stream.write("%s %d %s" % (result, self.testsRun, test.id()))
|
||||
if directive:
|
||||
self.output_stream.write(" # " + directive)
|
||||
self.output_stream.write("\n")
|
||||
self.output_stream.flush()
|
||||
def ok(self, test, directive=None):
|
||||
self.print_result("ok", test, directive)
|
||||
|
||||
def ok(self, test, directive = None):
|
||||
self.print_result("ok", test, directive)
|
||||
def not_ok(self, test):
|
||||
self.print_result("not ok", test)
|
||||
|
||||
def not_ok(self, test):
|
||||
self.print_result("not ok", test)
|
||||
def startTest(self, test):
|
||||
super(TAPTestResult, self).startTest(test)
|
||||
|
||||
def startTest(self, test):
|
||||
super(TAPTestResult, self).startTest(test)
|
||||
def stopTest(self, test):
|
||||
super(TAPTestResult, self).stopTest(test)
|
||||
if self.message_log == self.test_output_log:
|
||||
logs = [(self.message_log, self.message, "output")]
|
||||
else:
|
||||
logs = [
|
||||
(self.test_output_log, self.test_output, "test_output"),
|
||||
(self.message_log, self.message, "message"),
|
||||
]
|
||||
for log_mode, log, log_name in logs:
|
||||
if log_mode != LogMode.LogToError:
|
||||
output = log.getvalue()
|
||||
if len(output):
|
||||
if log_mode == LogMode.LogToYAML:
|
||||
self.print_raw(" ---\n")
|
||||
self.print_raw(" " + log_name + ": |\n")
|
||||
self.print_raw(
|
||||
" " + output.rstrip().replace("\n", "\n ") + "\n"
|
||||
)
|
||||
self.print_raw(" ...\n")
|
||||
elif log_mode == LogMode.LogToAttachment:
|
||||
self.print_raw(" ---\n")
|
||||
self.print_raw(" " + log_name + ":\n")
|
||||
self.print_raw(" File-Name: " + log_name + ".txt\n")
|
||||
self.print_raw(" File-Type: text/plain\n")
|
||||
self.print_raw(
|
||||
" File-Content: " + base64.b64encode(output) + "\n"
|
||||
)
|
||||
self.print_raw(" ...\n")
|
||||
else:
|
||||
self.print_raw(
|
||||
"# " + output.rstrip().replace("\n", "\n# ") + "\n"
|
||||
)
|
||||
# Truncate doesn't change the current stream position.
|
||||
# Seek to the beginning to avoid extensions on subsequent writes.
|
||||
log.seek(0)
|
||||
log.truncate(0)
|
||||
|
||||
def stopTest(self, test):
|
||||
super(TAPTestResult, self).stopTest(test)
|
||||
if self.message_log == self.test_output_log:
|
||||
logs = [(self.message_log, self.message, "output")]
|
||||
else:
|
||||
logs = [
|
||||
(self.test_output_log, self.test_output, "test_output"),
|
||||
(self.message_log, self.message, "message")
|
||||
]
|
||||
for log_mode, log, log_name in logs:
|
||||
if log_mode != LogMode.LogToError:
|
||||
output = log.getvalue()
|
||||
if len(output):
|
||||
if log_mode == LogMode.LogToYAML:
|
||||
self.print_raw(" ---\n")
|
||||
self.print_raw(" " + log_name + ": |\n")
|
||||
self.print_raw(" " + output.rstrip().replace("\n", "\n ") + "\n")
|
||||
self.print_raw(" ...\n")
|
||||
elif log_mode == LogMode.LogToAttachment:
|
||||
self.print_raw(" ---\n")
|
||||
self.print_raw(" " + log_name + ":\n")
|
||||
self.print_raw(" File-Name: " + log_name + ".txt\n")
|
||||
self.print_raw(" File-Type: text/plain\n")
|
||||
self.print_raw(" File-Content: " + base64.b64encode(output) + "\n")
|
||||
self.print_raw(" ...\n")
|
||||
else:
|
||||
self.print_raw("# " + output.rstrip().replace("\n", "\n# ") + "\n")
|
||||
# Truncate doesn't change the current stream position.
|
||||
# Seek to the beginning to avoid extensions on subsequent writes.
|
||||
log.seek(0)
|
||||
log.truncate(0)
|
||||
def addSuccess(self, test):
|
||||
super(TAPTestResult, self).addSuccess(test)
|
||||
self.ok(test)
|
||||
|
||||
def addSuccess(self, test):
|
||||
super(TAPTestResult, self).addSuccess(test)
|
||||
self.ok(test)
|
||||
def addError(self, test, err):
|
||||
super(TAPTestResult, self).addError(test, err)
|
||||
self.message.write(self.errors[-1][1] + "\n")
|
||||
self.not_ok(test)
|
||||
|
||||
def addError(self, test, err):
|
||||
super(TAPTestResult, self).addError(test, err)
|
||||
self.message.write(self.errors[-1][1] + "\n")
|
||||
self.not_ok(test)
|
||||
def addFailure(self, test, err):
|
||||
super(TAPTestResult, self).addFailure(test, err)
|
||||
self.message.write(self.failures[-1][1] + "\n")
|
||||
self.not_ok(test)
|
||||
|
||||
def addFailure(self, test, err):
|
||||
super(TAPTestResult, self).addFailure(test, err)
|
||||
self.message.write(self.failures[-1][1] + "\n")
|
||||
self.not_ok(test)
|
||||
def addSkip(self, test, reason):
|
||||
super(TAPTestResult, self).addSkip(test, reason)
|
||||
self.ok(test, "SKIP " + reason)
|
||||
|
||||
def addSkip(self, test, reason):
|
||||
super(TAPTestResult, self).addSkip(test, reason)
|
||||
self.ok(test, "SKIP " + reason)
|
||||
def addExpectedFailure(self, test, err):
|
||||
super(TAPTestResult, self).addExpectedFailure(test, err)
|
||||
self.ok(test)
|
||||
|
||||
def addExpectedFailure(self, test, err):
|
||||
super(TAPTestResult, self).addExpectedFailure(test, err)
|
||||
self.ok(test)
|
||||
|
||||
def addUnexpectedSuccess(self, test):
|
||||
super(TAPTestResult, self).addUnexpectedSuccess(test)
|
||||
self.message.write("Unexpected success" + "\n")
|
||||
self.not_ok(test)
|
||||
def addUnexpectedSuccess(self, test):
|
||||
super(TAPTestResult, self).addUnexpectedSuccess(test)
|
||||
self.message.write("Unexpected success" + "\n")
|
||||
self.not_ok(test)
|
||||
|
||||
|
||||
class TAPTestRunner(object):
|
||||
def __init__(self,
|
||||
message_log = LogMode.LogToYAML,
|
||||
test_output_log = LogMode.LogToDiagnostics,
|
||||
output_stream = sys.stdout, error_stream = sys.stderr):
|
||||
self.output_stream = output_stream
|
||||
self.error_stream = error_stream
|
||||
self.message_log = message_log
|
||||
self.test_output_log = test_output_log
|
||||
def __init__(
|
||||
self,
|
||||
message_log=LogMode.LogToYAML,
|
||||
test_output_log=LogMode.LogToDiagnostics,
|
||||
output_stream=sys.stdout,
|
||||
error_stream=sys.stderr,
|
||||
):
|
||||
self.output_stream = output_stream
|
||||
self.error_stream = error_stream
|
||||
self.message_log = message_log
|
||||
self.test_output_log = test_output_log
|
||||
|
||||
def run(self, test):
|
||||
result = TAPTestResult(
|
||||
self.output_stream,
|
||||
self.error_stream,
|
||||
self.message_log,
|
||||
self.test_output_log)
|
||||
test(result)
|
||||
result.printErrors()
|
||||
def run(self, test):
|
||||
result = TAPTestResult(
|
||||
self.output_stream,
|
||||
self.error_stream,
|
||||
self.message_log,
|
||||
self.test_output_log,
|
||||
)
|
||||
test(result)
|
||||
result.printErrors()
|
||||
|
||||
return result
|
||||
return result
|
||||
|
Reference in New Issue
Block a user