summaryrefslogtreecommitdiff
path: root/test/convert.py
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2024-02-25 17:40:19 +0100
committerJohn Wiegley <johnw@newartisans.com>2024-07-08 10:12:07 -0700
commit815305b94864556c994934c7a7c830da7de1d94e (patch)
tree6d85f089b05520416eee1f51f80636b357cda73d /test/convert.py
parent0b561c7304ec82807212bd070fc6a1684c67607b (diff)
downloadfork-ledger-815305b94864556c994934c7a7c830da7de1d94e.tar.gz
fork-ledger-815305b94864556c994934c7a7c830da7de1d94e.tar.bz2
fork-ledger-815305b94864556c994934c7a7c830da7de1d94e.zip
Use Python raw strings for regex methods argument
Diffstat (limited to 'test/convert.py')
-rwxr-xr-xtest/convert.py130
1 files changed, 65 insertions, 65 deletions
diff --git a/test/convert.py b/test/convert.py
index a54edaac..bdd7a15b 100755
--- a/test/convert.py
+++ b/test/convert.py
@@ -67,34 +67,34 @@ not_for_python = 0
class_name = None
for line in fd.readlines():
- if re.match('^#ifndef NOT_FOR_PYTHON', line):
+ if re.match(r'^#ifndef NOT_FOR_PYTHON', line):
not_for_python += 1
continue
elif not_for_python > 0:
- if re.match('^#endif // NOT_FOR_PYTHON', line):
+ if re.match(r'^#endif // NOT_FOR_PYTHON', line):
not_for_python -= 1
continue
- if re.match('^(using|CPP|[#{}/])', line):
+ if re.match(r'^(using|CPP|[#{}/])', line):
continue
- if re.match('^\s+[{}]\s+$', line):
+ if re.match(r'^\s+[{}]\s+$', line):
continue
- if not re.search('assert', line):
- match = re.match('^};', line)
+ if not re.search(r'assert', line):
+ match = re.match(r'^};', line)
if match:
continue
- match = re.match('BOOST_.*_TEST_SUITE', line)
+ match = re.match(r'BOOST_.*_TEST_SUITE', line)
if match:
continue
- match = re.match('^struct (.*?) {', line)
+ match = re.match(r'^struct (.*?) {', line)
if match:
class_name = match.group(1)
continue
if class_name:
- match = re.search('(~)?%s\(\) {' % class_name, line)
+ match = re.search(r'(~)?%s\(\) {' % class_name, line)
if match:
if match.group(1):
fo.write(' def tearDown(self):\n')
@@ -102,17 +102,17 @@ for line in fd.readlines():
fo.write(' def setUp(self):\n')
continue
- match = re.match('BOOST_AUTO_TEST_CASE\((.+?)\)', line)
+ match = re.match(r'BOOST_AUTO_TEST_CASE\((.+?)\)', line)
if match:
fo.write(' def %s(self):\n' % match.group(1))
continue
- match = re.match('void [^:]+::(test[^(]+|setUp|tearDown)\(\)', line)
+ match = re.match(r'void [^:]+::(test[^(]+|setUp|tearDown)\(\)', line)
if match:
fo.write(' def %s(self):\n' % match.group(1))
continue
- match = re.search(' ([a-z:_<>]+?)&?\s+([a-z0-9_]+)(\((.+?)\))?;', line)
+ match = re.search(r' ([a-z:_<>]+?)&?\s+([a-z0-9_]+)(\((.+?)\))?;', line)
if match:
if match.group(1) != "std::string":
line = ' %s = %s(%s)\n' % (match.group(2), match.group(1),
@@ -120,79 +120,79 @@ for line in fd.readlines():
else:
line = ''
- match = re.search(' ([a-z:_<>]+?)&?\s+([a-z0-9]+)\s*=\s*([^(]+);', line)
+ match = re.search(r' ([a-z:_<>]+?)&?\s+([a-z0-9]+)\s*=\s*([^(]+);', line)
if match:
line = ' %s = %s(%s)\n' % (match.group(2), match.group(1),
match.group(3))
- match = re.search(' ([a-z:_<>]+?)\s+([a-z0-9]+)\s*=\s*(.+?)$', line)
+ match = re.search(r' ([a-z:_<>]+?)\s+([a-z0-9]+)\s*=\s*(.+?)$', line)
if match:
line = ' %s = %s\n' % (match.group(2), match.group(3))
- line = re.sub('BOOST_CHECK_NE', 'self.assertNotEqual', line)
- line = re.sub('BOOST_CHECK_EQUAL', 'self.assertEqual', line)
+ line = re.sub(r'BOOST_CHECK_NE', 'self.assertNotEqual', line)
+ line = re.sub(r'BOOST_CHECK_EQUAL', 'self.assertEqual', line)
line = re.sub('BOOST_CHECK_THROW\(([^,]+), ([^,)]+?)\)',
'self.assertRaises(\\2, lambda: \\1)', line)
- line = re.sub('BOOST_CHECK', 'self.assertTrue', line)
+ line = re.sub(r'BOOST_CHECK', 'self.assertTrue', line)
# jww (2010-06-20): Determine this list automatically by scanning
# the class_ lines in src/py_*.cc
- line = re.sub('amount_t::precision_t\(([^)]+?)\)', '\\1', line)
- line = re.sub('amount_t::', 'Amount.', line)
- line = re.sub('Amount\.PARSE_', 'AmountParse.', line)
- line = re.sub('commodity_t\(([^)]+?)\)', '\\1', line)
- line = re.sub('commodity_t::', 'Commodity.', line)
- line = re.sub('balance_t::', 'Balance.', line)
- line = re.sub('balance_pair_t::', 'BalancePair.', line)
- line = re.sub('value_t::', 'Value.', line)
-
- line = re.sub('amount_t', 'Amount', line)
- line = re.sub('commodity_t', 'Commodity', line)
- line = re.sub('balance_t', 'Balance', line)
- line = re.sub('balance_pair_t', 'BalancePair', line)
- line = re.sub('value_t', 'Value', line)
-
- line = re.sub("PARSE_DEFAULT", "ParseFlags.Default", line)
- line = re.sub("PARSE_PARTIAL", "ParseFlags.Partial", line)
- line = re.sub("PARSE_SINGLE", "ParseFlags.Single", line)
- line = re.sub("PARSE_NO_MIGRATE", "ParseFlags.NoMigrate", line)
- line = re.sub("PARSE_NO_REDUCE", "ParseFlags.NoReduce", line)
- line = re.sub("PARSE_NO_ASSIGN", "ParseFlags.NoAssign", line)
- line = re.sub("PARSE_NO_DATES", "ParseFlags.NoDates", line)
- line = re.sub("PARSE_OP_CONTEXT", "ParseFlags.OpContext", line)
- line = re.sub("PARSE_SOFT_FAIL", "ParseFlags.SoftFail", line)
-
- line = re.sub('ledger::', '', line)
- line = re.sub('std::istringstream', 'StringIO', line)
- line = re.sub('std::ostringstream', 'StringIO', line)
+ line = re.sub(r'amount_t::precision_t\(([^)]+?)\)', '\\1', line)
+ line = re.sub(r'amount_t::', 'Amount.', line)
+ line = re.sub(r'Amount\.PARSE_', 'AmountParse.', line)
+ line = re.sub(r'commodity_t\(([^)]+?)\)', '\\1', line)
+ line = re.sub(r'commodity_t::', 'Commodity.', line)
+ line = re.sub(r'balance_t::', 'Balance.', line)
+ line = re.sub(r'balance_pair_t::', 'BalancePair.', line)
+ line = re.sub(r'value_t::', 'Value.', line)
+
+ line = re.sub(r'amount_t', 'Amount', line)
+ line = re.sub(r'commodity_t', 'Commodity', line)
+ line = re.sub(r'balance_t', 'Balance', line)
+ line = re.sub(r'balance_pair_t', 'BalancePair', line)
+ line = re.sub(r'value_t', 'Value', line)
+
+ line = re.sub(r'PARSE_DEFAULT', "ParseFlags.Default", line)
+ line = re.sub(r'PARSE_PARTIAL', "ParseFlags.Partial", line)
+ line = re.sub(r'PARSE_SINGLE', "ParseFlags.Single", line)
+ line = re.sub(r'PARSE_NO_MIGRATE', "ParseFlags.NoMigrate", line)
+ line = re.sub(r'PARSE_NO_REDUCE', "ParseFlags.NoReduce", line)
+ line = re.sub(r'PARSE_NO_ASSIGN', "ParseFlags.NoAssign", line)
+ line = re.sub(r'PARSE_NO_DATES', "ParseFlags.NoDates", line)
+ line = re.sub(r'PARSE_OP_CONTEXT', "ParseFlags.OpContext", line)
+ line = re.sub(r'PARSE_SOFT_FAIL', "ParseFlags.SoftFail", line)
+
+ line = re.sub(r'ledger::', '', line)
+ line = re.sub(r'std::istringstream', 'StringIO', line)
+ line = re.sub(r'std::ostringstream', 'StringIO', line)
line = re.sub('set_session_context\(&session\)',
'self.testSession = session()\n set_session_context(self.testSession)', line)
line = re.sub('set_session_context\(\)',
'set_session_context()\n self.testSession = None', line)
- line = re.sub('([a-z_]+?)_t\b', '\\1', line)
- line = re.sub('("[^"]+")', 'u\\1', line)
- line = re.sub('std::string\(([^)]+?)\)', '\\1', line)
- line = re.sub('string\(([^)]+?)\)', '\\1', line)
- line = re.sub('\.print\(([^)]+?)\)', '.print_(\\1)', line)
- line = re.sub('true', 'True', line)
- line = re.sub('false', 'False', line)
- line = re.sub('CURRENT_TIME\(\)', 'datetime.now()', line)
- line = re.sub('CURRENT_DATE\(\)', 'date.today()', line)
- line = re.sub('commodity\(\)', 'commodity', line)
- line = re.sub('precision\(\)', 'precision', line)
- line = re.sub('([0-9]+)[FL]', '\\1', line)
- line = re.sub('([0-9]+)UL', '\\1L', line)
- line = re.sub(';', '', line)
- line = re.sub('//', '#', line)
- line = re.sub('->', '.', line)
+ line = re.sub(r'([a-z_]+?)_t\b', '\\1', line)
+ line = re.sub(r'('[^"]+")', 'u\\1', line)
+ line = re.sub(r'std::string\(([^)]+?)\)', '\\1', line)
+ line = re.sub(r'string\(([^)]+?)\)', '\\1', line)
+ line = re.sub(r'\.print\(([^)]+?)\)', '.print_(\\1)', line)
+ line = re.sub(r'true', 'True', line)
+ line = re.sub(r'false', 'False', line)
+ line = re.sub(r'CURRENT_TIME\(\)', 'datetime.now()', line)
+ line = re.sub(r'CURRENT_DATE\(\)', 'date.today()', line)
+ line = re.sub(r'commodity\(\)', 'commodity', line)
+ line = re.sub(r'precision\(\)', 'precision', line)
+ line = re.sub(r'([0-9]+)[FL]', '\\1', line)
+ line = re.sub(r'([0-9]+)UL', '\\1L', line)
+ line = re.sub(r';', '', line)
+ line = re.sub(r'//', '#', line)
+ line = re.sub(r'->', '.', line)
line = re.sub('(\s+|\()(\S+?) \? (.+?) : (.+?)\)',
'\\1\\3 if \\2 else \\4)', line)
- line = re.sub('if \((.+?)\)( {)?$', 'if \\1:', line)
- line = re.sub('(} )?else( {)?$', 'else:', line)
+ line = re.sub(r'if \((.+?)\)( {)?$', 'if \\1:', line)
+ line = re.sub(r'(} )?else( {)?$', 'else:', line)
- line = re.sub('amount_error', 'exceptions.ArithmeticError', line)
+ line = re.sub(r'amount_error', 'exceptions.ArithmeticError', line)
- match = re.match('^ ', line)
+ match = re.match(r'^ ', line)
if match:
fo.write(' ' + line)
else: