From 98b3a644da555010a5e061ab751b4f5306e914e0 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 13 Sep 2019 16:22:41 -0400 Subject: [PATCH 1/5] add some tests --- setup.py | 1 + .../allmydata}/ported-modules.txt | 0 src/allmydata/test/test_python3.py | 116 ++++++++++++++++++ 3 files changed, 117 insertions(+) rename {misc/python3 => src/allmydata}/ported-modules.txt (100%) create mode 100644 src/allmydata/test/test_python3.py diff --git a/setup.py b/setup.py index b9d2baa8c..330df3567 100644 --- a/setup.py +++ b/setup.py @@ -369,6 +369,7 @@ setup(name="tahoe-lafs", # also set in __init__.py "static/img/*.png", "static/css/*.css", ] + "allmydata": ["ported-modules.txt"], }, include_package_data=True, setup_requires=setup_requires, diff --git a/misc/python3/ported-modules.txt b/src/allmydata/ported-modules.txt similarity index 100% rename from misc/python3/ported-modules.txt rename to src/allmydata/ported-modules.txt diff --git a/src/allmydata/test/test_python3.py b/src/allmydata/test/test_python3.py new file mode 100644 index 000000000..585bbfd77 --- /dev/null +++ b/src/allmydata/test/test_python3.py @@ -0,0 +1,116 @@ +""" +Tests related to the Python 3 porting effort itself. +""" + +from sys import ( + modules, +) +from inspect import ( + getsource, +) +from pkg_resources import ( + resource_stream, +) + +from twisted.python.reflect import ( + namedAny, +) +from twisted.python.modules import ( + getModule, +) +from twisted.trial.unittest import ( + SynchronousTestCase, +) + + +class Python3PortingEffortTests(SynchronousTestCase): + def test_finished_porting(self): + """ + Tahoe-LAFS has been ported to Python 3. + """ + tahoe_lafs_module_names = set(all_module_names("allmydata")) + ported_names = set(ported_module_names()) + self.assertEqual( + tahoe_lafs_module_names - ported_names, + set(), + "Some unported modules remain: {}".format( + unported_report( + tahoe_lafs_module_names, + ported_names, + ), + ), + ) + test_finished_porting.todo = "https://tahoe-lafs.org/trac/tahoe-lafs/milestone/Support%20Python%203 should be completed" + + def test_ported_modules_exist(self): + """ + All modules listed as ported exist and belong to Tahoe-LAFS. + """ + tahoe_lafs_module_names = set(all_module_names("allmydata")) + ported_names = set(ported_module_names()) + unknown = ported_names - tahoe_lafs_module_names + self.assertEqual( + unknown, + set(), + "Some supposedly-ported modules weren't found: {}.".format(sorted(unknown)), + ) + + def test_ported_modules_distinct(self): + """ + The ported modules list doesn't contain duplicates. + """ + ported_names_list = ported_module_names() + ported_names_list.sort() + ported_names_set = set(ported_names_list) + ported_names_unique_list = list(ported_names_set) + ported_names_unique_list.sort() + self.assertEqual( + ported_names_list, + ported_names_unique_list, + ) + + +def all_module_names(toplevel): + """ + :param unicode toplevel: The name of a top-level Python package. + + :return iterator[unicode]: An iterator of ``unicode`` giving the names of + all modules within the given top-level Python package. + """ + allmydata = getModule(toplevel) + for module in allmydata.walkModules(): + yield module.name.decode("utf-8") + + +def ported_module_names(): + """ + :return list[unicode]: A ``set`` of ``unicode`` giving the names of + Tahoe-LAFS modules which have been ported to Python 3. + """ + return resource_stream( + "allmydata", + u"ported-modules.txt", + ).read().splitlines() + + +def unported_report(tahoe_lafs_module_names, ported_names): + return """ +Ported files: {} / {} +Ported lines: {} / {} +""".format( + len(ported_names), + len(tahoe_lafs_module_names), + sum(map(count_lines, ported_names)), + sum(map(count_lines, tahoe_lafs_module_names)), +) + +def count_lines(module_name): + module = getModule(module_name) + try: + source = module.filePath.getContent() + except Exception as e: + print(module_name, e) + return 0 + lines = source.splitlines() + nonblank = filter(None, lines) + return len(nonblank) From 971ead3148bdca28d83219ef22976ae58127f40f Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 16 Sep 2019 10:03:06 -0400 Subject: [PATCH 2/5] Get the syntax right --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 330df3567..4cd9a5fdb 100644 --- a/setup.py +++ b/setup.py @@ -368,7 +368,7 @@ setup(name="tahoe-lafs", # also set in __init__.py "static/*.js", "static/*.png", "static/*.css", "static/img/*.png", "static/css/*.css", - ] + ], "allmydata": ["ported-modules.txt"], }, include_package_data=True, From 8a1fa9a41e3c7a8855cabd62b4d44414b8da3f26 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 16 Sep 2019 10:25:34 -0400 Subject: [PATCH 3/5] remove unused imports --- src/allmydata/test/test_python3.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/allmydata/test/test_python3.py b/src/allmydata/test/test_python3.py index 585bbfd77..8a25af889 100644 --- a/src/allmydata/test/test_python3.py +++ b/src/allmydata/test/test_python3.py @@ -2,19 +2,10 @@ Tests related to the Python 3 porting effort itself. """ -from sys import ( - modules, -) -from inspect import ( - getsource, -) from pkg_resources import ( resource_stream, ) -from twisted.python.reflect import ( - namedAny, -) from twisted.python.modules import ( getModule, ) From 1de51cd24d9cc705a2bc298e6c233152c9274507 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 17 Sep 2019 11:36:09 -0400 Subject: [PATCH 4/5] follow the renaming --- misc/python3/tahoe-depgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/python3/tahoe-depgraph.py b/misc/python3/tahoe-depgraph.py index 0abf1515b..1bfe89c73 100644 --- a/misc/python3/tahoe-depgraph.py +++ b/misc/python3/tahoe-depgraph.py @@ -111,7 +111,7 @@ def main(target): json_dump(mf.as_json(), outfile) outfile.write('\n') - ported_modules_path = os.path.join(target, "misc", "python3", "ported-modules.txt") + ported_modules_path = os.path.join(target, "src", "allmydata", "ported-modules.txt") with open(ported_modules_path) as ported_modules: port_status = dict.fromkeys((line.strip() for line in ported_modules), "ported") with open('tahoe-ported.json', 'wb') as outfile: From f059327747391f31ddfb49e9040c4f03223e3655 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 17 Sep 2019 11:36:31 -0400 Subject: [PATCH 5/5] news fragment --- newsfragments/3255.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3255.minor diff --git a/newsfragments/3255.minor b/newsfragments/3255.minor new file mode 100644 index 000000000..e69de29bb