diff options
author | Alexis Hildebrandt <afh@surryhill.net> | 2023-12-04 12:23:56 +0100 |
---|---|---|
committer | Alexis Hildebrandt <afh@surryhill.net> | 2023-12-04 12:23:56 +0100 |
commit | 3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34 (patch) | |
tree | 287e867ef25bf2ecbaa9364f257aefdfb23ef97f /test | |
parent | 8bbd3fed06087243861a6d6ec9c58dd8858ab34c (diff) | |
download | fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.gz fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.bz2 fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.zip |
Migrate Python scripts to Python 3
Diffstat (limited to 'test')
-rwxr-xr-x | test/CheckBaselineTests.py | 3 | ||||
-rw-r--r-- | test/CheckComments.py | 46 | ||||
-rwxr-xr-x | test/CheckManpage.py | 3 | ||||
-rwxr-xr-x | test/CheckOptions.py | 19 | ||||
-rwxr-xr-x | test/CheckTexinfo.py | 3 | ||||
-rwxr-xr-x | test/ConfirmTests.py | 10 | ||||
-rwxr-xr-x | test/DocTests.py | 3 | ||||
-rwxr-xr-x | test/GenerateTests.py | 2 | ||||
-rwxr-xr-x | test/LedgerHarness.py | 3 | ||||
-rwxr-xr-x | test/RegressTests.py | 3 | ||||
-rwxr-xr-x | test/convert.py | 2 | ||||
-rw-r--r-- | test/python/JournalTest.py | 2 | ||||
-rw-r--r-- | test/python/PostingTest.py | 2 | ||||
-rw-r--r-- | test/python/TransactionTest.py | 2 | ||||
-rw-r--r-- | test/regress/B21BF389.py | 3 |
15 files changed, 52 insertions, 54 deletions
diff --git a/test/CheckBaselineTests.py b/test/CheckBaselineTests.py index fa9fa2bc..9f52dd10 100755 --- a/test/CheckBaselineTests.py +++ b/test/CheckBaselineTests.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import sys import re diff --git a/test/CheckComments.py b/test/CheckComments.py index 446137b0..9bcfcbb3 100644 --- a/test/CheckComments.py +++ b/test/CheckComments.py @@ -1,20 +1,19 @@ +#!/usr/bin/env python3 + import sys import re import os +import argparse -ok = 100.0 -if sys.argv[1] == '-l': - ok = float(sys.argv[2]) - sys.argv = [sys.argv[0]] + sys.argv[3:] - -debug = False -if sys.argv[1] == '-v': - debug = True - sys.argv = [sys.argv[0]] + sys.argv[2:] +parser = argparse.ArgumentParser( prog='CheckComments') +parser.add_argument('-v', '--debug', dest='debug', action='store_true') +parser.add_argument('-l', '--limit', dest='ok', type=float, default=100.0) +parser.add_argument('path', nargs='+', help='Path to source file to check comments') +args = parser.parse_args() errors = 0 -for path in sys.argv[1:]: +for path in args.path: other_depth = 0 brace_depth = 0 code_count = 0 @@ -26,6 +25,7 @@ for path in sys.argv[1:]: ctor_dtor = False linenum = 0 + print(f'checking {path}') fd = open(path, 'r') for line in fd.readlines(): linenum += 1 @@ -48,48 +48,48 @@ for path in sys.argv[1:]: match = re.search('(namespace|enum|class|struct|union)', line) if match: kind = match.group(1) - if debug: print "kind =", kind + if args.debug: print("kind =", kind) elif kind == "function": match = re.search('(\S+)\(', line) if match: function_name = match.group(1) long_comments[function_name] = comment_count comment_count = 0 - if debug: print "name found %s" % function_name + if args.debug: print("name found %s" % function_name) if re.search('{', line) and not re.search('@{', line): if kind == "function": brace_depth += 1 - if debug: print "brace_depth =", brace_depth + if args.debug: print("brace_depth =", brace_depth) else: other_depth += 1 kind = "function" - if debug: print "other_depth =", other_depth + if args.debug: print("other_depth =", other_depth) if re.search('}', line) and not re.search('@}', line): if brace_depth > 0: brace_depth -= 1 - if debug: print "brace_depth =", brace_depth + if args.debug: print("brace_depth =", brace_depth) if brace_depth == 0: - if debug: print "function done" + if args.debug: print("function done") if function_name in long_comments: comment_count += long_comments[function_name] if code_count == 0: - percent = ok - print "%7s %4d/%4d %s:%d: %s" % \ + percent = args.ok + print("%7s %4d/%4d %s:%d: %s" % \ ("empty", comment_count, code_count, os.path.basename(path), linenum, - function_name) + function_name)) errors += 1 else: percent = 100.0 * (float(comment_count) / float(code_count)) - if percent < ok and not ctor_dtor: - print "%6.0f%% %4d/%4d %s:%d: %s" % \ + if percent < args.ok and not ctor_dtor: + print("%6.0f%% %4d/%4d %s:%d: %s" % \ (percent, comment_count, code_count, os.path.basename(path), linenum, - function_name) + function_name)) errors += 1 code_count = 0 comment_count = 0 @@ -98,7 +98,7 @@ for path in sys.argv[1:]: ctor_dtor = False else: other_depth -= 1 - if debug: print "other_depth =", other_depth + if args.debug: print("other_depth =", other_depth) if brace_depth > 0: if re.search("TRACE_[CD]TOR", line): diff --git a/test/CheckManpage.py b/test/CheckManpage.py index 3da9d872..e519a00a 100755 --- a/test/CheckManpage.py +++ b/test/CheckManpage.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import sys import re diff --git a/test/CheckOptions.py b/test/CheckOptions.py index 3f08fb0d..faf1630e 100755 --- a/test/CheckOptions.py +++ b/test/CheckOptions.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import re import os @@ -40,7 +39,7 @@ class CheckOptions (object): for source_file in ['session', 'report']: command.append(os.path.join(self.source, 'src', '%s.cc' % source_file)) try: - output = subprocess.check_output(command).split('\n'); + output = subprocess.check_output(command, universal_newlines=True).split('\n') except subprocess.CalledProcessError: output = '' @@ -58,7 +57,7 @@ class CheckOptions (object): def ledger_functions(self): command = shlex.split('grep --no-filename fn_ %s' % (os.path.join(self.source, 'src', 'report.h'))) try: - output = subprocess.check_output(command).split('\n'); + output = subprocess.check_output(command, universal_newlines=True).split('\n'); except subprocess.CalledProcessError: output = '' @@ -74,7 +73,13 @@ class CheckOptions (object): else: options.remove(option) known_alternates = self.find_alternates() - self.unknown_options = {option for option in options if option not in known_alternates} + self.unknown_options = options - known_alternates + self.missing_options -= { + # The option --explicit is a no-op as of March 2020 and is + # therefore intentionally undocumented. + # For details see commit 43b07fbab3b4c144eca4a771524e59c531ffa074 + 'explicit' + } functions = self.find_functions(self.source_file) for function in self.ledger_functions(): @@ -82,8 +87,8 @@ class CheckOptions (object): self.missing_functions.add(function) else: functions.remove(function) - known_functions = ['tag', 'has_tag', 'meta', 'has_meta'] - self.unknown_functions = {function for function in functions if function not in known_functions} + known_functions = {'tag', 'has_tag', 'meta', 'has_meta'} + self.unknown_functions = functions - known_functions if len(self.missing_options): print("Missing %s option entries for:%s%s\n" % (self.source_type, self.sep, self.sep.join(sorted(list(self.missing_options))))) diff --git a/test/CheckTexinfo.py b/test/CheckTexinfo.py index fa709e1b..82c7a286 100755 --- a/test/CheckTexinfo.py +++ b/test/CheckTexinfo.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import sys import re diff --git a/test/ConfirmTests.py b/test/ConfirmTests.py index e82479ed..0dc2b9f5 100755 --- a/test/ConfirmTests.py +++ b/test/ConfirmTests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # This script confirms both that the register report "adds up", and that its # final balance is the same as what the balance report shows. @@ -56,8 +56,8 @@ def confirm_report(command): if re.search(' -[VGB] ', command) and diff < 0.015: diff = 0.0 if diff > 0.001: - print("DISCREPANCY: %.3f (%.3f - %.3f) at line %d:" % \) - (running_total - total, running_total, total, index) + print("DISCREPANCY: %.3f (%.3f - %.3f) at line %d:" % \ + (running_total - total, running_total, total, index)) print(line,) running_total = total failure = True @@ -78,8 +78,8 @@ def confirm_report(command): diff = 0.0 if diff > 0.001: print() - print("DISCREPANCY: %.3f (%.3f - %.3f) between register and balance" % \) - (balance_total - running_total, balance_total, running_total) + print("DISCREPANCY: %.3f (%.3f - %.3f) between register and balance" % \ + (balance_total - running_total, balance_total, running_total)) print(last_line,) failure = True diff --git a/test/DocTests.py b/test/DocTests.py index daecdd90..e12a4ae4 100755 --- a/test/DocTests.py +++ b/test/DocTests.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 from io import open diff --git a/test/GenerateTests.py b/test/GenerateTests.py index 2b966e35..9bd4a7bc 100755 --- a/test/GenerateTests.py +++ b/test/GenerateTests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # This script confirms both that the register report "adds up", and that its # final balance is the same as what the balance report shows. diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 5051fc8b..0da32e8a 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import sys import os diff --git a/test/RegressTests.py b/test/RegressTests.py index 849c4137..a3998f1f 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 from io import open diff --git a/test/convert.py b/test/convert.py index 85e52701..a54edaac 100755 --- a/test/convert.py +++ b/test/convert.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # convert.py: This script converts a Boost.Test unit test into an # equivalent Python unit test. diff --git a/test/python/JournalTest.py b/test/python/JournalTest.py index 84ad2f43..59442968 100644 --- a/test/python/JournalTest.py +++ b/test/python/JournalTest.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import unittest diff --git a/test/python/PostingTest.py b/test/python/PostingTest.py index 0dd18112..f6b9bc04 100644 --- a/test/python/PostingTest.py +++ b/test/python/PostingTest.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import unittest import operator diff --git a/test/python/TransactionTest.py b/test/python/TransactionTest.py index c87f8c4b..12069389 100644 --- a/test/python/TransactionTest.py +++ b/test/python/TransactionTest.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import unittest import operator diff --git a/test/regress/B21BF389.py b/test/regress/B21BF389.py index 11208e91..e130b7b3 100644 --- a/test/regress/B21BF389.py +++ b/test/regress/B21BF389.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 import sys import ledger |