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:
Philip Withnall
2020-11-17 15:07:09 +00:00
parent 053d2ae2b4
commit 905b22a17e
26 changed files with 6928 additions and 4875 deletions

View File

@@ -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())