mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix problems detected by pylint 2.8.1.
This commit is contained in:
parent
eed0bf580b
commit
4e7dc24383
@ -61,51 +61,51 @@ def get_checks(content, sol_file_path):
|
|||||||
constructors.append(line)
|
constructors.append(line)
|
||||||
if line.startswith("ABI_CHECK") or line.startswith("BOOST_REQUIRE"):
|
if line.startswith("ABI_CHECK") or line.startswith("BOOST_REQUIRE"):
|
||||||
checks.append(line)
|
checks.append(line)
|
||||||
sol_file = open(sol_file_path, "r")
|
with open(sol_file_path, "r") as sol_file:
|
||||||
sol_constructors = []
|
sol_constructors = []
|
||||||
sol_checks = []
|
sol_checks = []
|
||||||
inside_expectations = False
|
inside_expectations = False
|
||||||
for line in sol_file.readlines():
|
for line in sol_file.readlines():
|
||||||
if line.startswith("// constructor()"):
|
if line.startswith("// constructor()"):
|
||||||
sol_constructors.append(line)
|
sol_constructors.append(line)
|
||||||
elif inside_expectations and line.startswith("// "):
|
elif inside_expectations and line.startswith("// "):
|
||||||
sol_checks.append(line)
|
sol_checks.append(line)
|
||||||
if line.startswith("// ----"):
|
if line.startswith("// ----"):
|
||||||
inside_expectations = True
|
inside_expectations = True
|
||||||
sol_file.close()
|
sol_file.close()
|
||||||
if len(constructors) == len(sol_constructors) == 1:
|
if len(constructors) == len(sol_constructors) == 1:
|
||||||
checks.insert(0, constructors[0])
|
checks.insert(0, constructors[0])
|
||||||
sol_checks.insert(0, sol_constructors[0])
|
sol_checks.insert(0, sol_constructors[0])
|
||||||
return checks, sol_checks
|
return checks, sol_checks
|
||||||
|
|
||||||
|
|
||||||
def show_test(name, content, sol_file_path, current_test, test_count):
|
def show_test(name, content, sol_file_path, current_test, test_count):
|
||||||
cpp_file = tempfile.NamedTemporaryFile(delete=False)
|
with tempfile.NamedTemporaryFile(delete=False) as cpp_file:
|
||||||
cpp_file.write(content.encode())
|
cpp_file.write(content.encode())
|
||||||
cpp_file.close()
|
cpp_file.close()
|
||||||
|
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
print(str(current_test) + " / " + str(test_count) + " - " + name + "\n")
|
print(str(current_test) + " / " + str(test_count) + " - " + name + "\n")
|
||||||
diff_env = os.getenv('DIFF', "/usr/local/bin/colordiff -a -d -w -y -W 200 ")
|
diff_env = os.getenv('DIFF', "/usr/local/bin/colordiff -a -d -w -y -W 200 ")
|
||||||
os.system(diff_env + " " + cpp_file.name + " " + sol_file_path)
|
os.system(diff_env + " " + cpp_file.name + " " + sol_file_path)
|
||||||
os.unlink(cpp_file.name)
|
os.unlink(cpp_file.name)
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
checks, sol_checks = get_checks(content, sol_file_path)
|
checks, sol_checks = get_checks(content, sol_file_path)
|
||||||
|
|
||||||
if len(checks) == len(sol_checks):
|
if len(checks) == len(sol_checks):
|
||||||
for i in range(0, len(checks)):
|
for i in range(0, len(checks)):
|
||||||
print(colorize(checks[i].strip(), sol_checks[i].strip(), i))
|
print(colorize(checks[i].strip(), sol_checks[i].strip(), i))
|
||||||
else:
|
else:
|
||||||
print("warning: check count not matching. this should not happen!")
|
print("warning: check count not matching. this should not happen!")
|
||||||
|
|
||||||
what = ""
|
what = ""
|
||||||
print("\nContinue? (ENTER) Abort? (ANY OTHER KEY)")
|
print("\nContinue? (ENTER) Abort? (ANY OTHER KEY)")
|
||||||
while what != '\n':
|
while what != '\n':
|
||||||
what = getkey()
|
what = getkey()
|
||||||
if what != '\n':
|
if what != '\n':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
def get_tests(e2e_path):
|
def get_tests(e2e_path):
|
||||||
@ -118,40 +118,40 @@ def get_tests(e2e_path):
|
|||||||
|
|
||||||
def process_input_file(e2e_path, input_file, interactive):
|
def process_input_file(e2e_path, input_file, interactive):
|
||||||
tests = get_tests(e2e_path)
|
tests = get_tests(e2e_path)
|
||||||
cpp_file = open(input_file, "r")
|
with open(input_file, "r") as cpp_file:
|
||||||
inside_test = False
|
inside_test = False
|
||||||
test_name = ""
|
test_name = ""
|
||||||
inside_extracted_test = False
|
inside_extracted_test = False
|
||||||
new_lines = 0
|
new_lines = 0
|
||||||
count = 0
|
count = 0
|
||||||
test_content = ""
|
test_content = ""
|
||||||
for line in cpp_file.readlines():
|
for line in cpp_file.readlines():
|
||||||
test = re.search(r'BOOST_AUTO_TEST_CASE\((.*)\)', line, re.M | re.I)
|
test = re.search(r'BOOST_AUTO_TEST_CASE\((.*)\)', line, re.M | re.I)
|
||||||
if test:
|
if test:
|
||||||
test_name = test.group(1)
|
test_name = test.group(1)
|
||||||
inside_test = True
|
inside_test = True
|
||||||
inside_extracted_test = inside_test & (test_name in tests)
|
inside_extracted_test = inside_test & (test_name in tests)
|
||||||
if inside_extracted_test:
|
if inside_extracted_test:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
|
||||||
if interactive and inside_extracted_test:
|
|
||||||
test_content = test_content + line
|
|
||||||
|
|
||||||
if not inside_extracted_test:
|
|
||||||
if line == "\n":
|
|
||||||
new_lines = new_lines + 1
|
|
||||||
else:
|
|
||||||
new_lines = 0
|
|
||||||
if not interactive and new_lines <= 1:
|
|
||||||
sys.stdout.write(line)
|
|
||||||
|
|
||||||
if line == "}\n":
|
|
||||||
if interactive and inside_extracted_test:
|
if interactive and inside_extracted_test:
|
||||||
show_test(test_name, test_content.strip(), e2e_path + "/" + test_name + ".sol", count, len(tests))
|
test_content = test_content + line
|
||||||
test_content = ""
|
|
||||||
inside_test = False
|
if not inside_extracted_test:
|
||||||
cpp_file.close()
|
if line == "\n":
|
||||||
sys.stdout.flush()
|
new_lines = new_lines + 1
|
||||||
|
else:
|
||||||
|
new_lines = 0
|
||||||
|
if not interactive and new_lines <= 1:
|
||||||
|
sys.stdout.write(line)
|
||||||
|
|
||||||
|
if line == "}\n":
|
||||||
|
if interactive and inside_extracted_test:
|
||||||
|
show_test(test_name, test_content.strip(), e2e_path + "/" + test_name + ".sol", count, len(tests))
|
||||||
|
test_content = ""
|
||||||
|
inside_test = False
|
||||||
|
cpp_file.close()
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
@ -75,38 +75,38 @@ class TraceAnalyser:
|
|||||||
self.ready = False
|
self.ready = False
|
||||||
|
|
||||||
def analyse(self):
|
def analyse(self):
|
||||||
trace_file = open(self.file, "r")
|
with open(self.file, "r") as trace_file:
|
||||||
trace = None
|
trace = None
|
||||||
test_case = None
|
test_case = None
|
||||||
for line in trace_file.readlines():
|
for line in trace_file.readlines():
|
||||||
test = re.search(r'Entering test case "(.*)"', line, re.M | re.I)
|
test = re.search(r'Entering test case "(.*)"', line, re.M | re.I)
|
||||||
if test:
|
if test:
|
||||||
test_name = test.group(1)
|
test_name = test.group(1)
|
||||||
test_case = TestCase(test_name)
|
test_case = TestCase(test_name)
|
||||||
self.tests[test_name] = test_case
|
self.tests[test_name] = test_case
|
||||||
|
|
||||||
metadata = re.search(r'\s*metadata:\s*(.*)$', line, re.M | re.I)
|
metadata = re.search(r'\s*metadata:\s*(.*)$', line, re.M | re.I)
|
||||||
if metadata:
|
if metadata:
|
||||||
test_case.metadata = json.loads(metadata.group(1))
|
test_case.metadata = json.loads(metadata.group(1))
|
||||||
del test_case.metadata["sources"]
|
del test_case.metadata["sources"]
|
||||||
del test_case.metadata["compiler"]["version"]
|
del test_case.metadata["compiler"]["version"]
|
||||||
|
|
||||||
create = re.search(r'CREATE\s*([a-fA-F0-9]*):', line, re.M | re.I)
|
create = re.search(r'CREATE\s*([a-fA-F0-9]*):', line, re.M | re.I)
|
||||||
if create:
|
if create:
|
||||||
trace = test_case.add_trace("create", create.group(1))
|
trace = test_case.add_trace("create", create.group(1))
|
||||||
|
|
||||||
call = re.search(r'CALL\s*([a-fA-F0-9]*)\s*->\s*([a-fA-F0-9]*):', line, re.M | re.I)
|
call = re.search(r'CALL\s*([a-fA-F0-9]*)\s*->\s*([a-fA-F0-9]*):', line, re.M | re.I)
|
||||||
if call:
|
if call:
|
||||||
trace = test_case.add_trace("call", call.group(1)) # + "->" + call.group(2))
|
trace = test_case.add_trace("call", call.group(1)) # + "->" + call.group(2))
|
||||||
|
|
||||||
if not create and not call:
|
if not create and not call:
|
||||||
self.parse_parameters(line, trace)
|
self.parse_parameters(line, trace)
|
||||||
|
|
||||||
trace_file.close()
|
trace_file.close()
|
||||||
|
|
||||||
print(self.file + ":", len(self.tests), "test-cases.")
|
print(self.file + ":", len(self.tests), "test-cases.")
|
||||||
|
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_parameters(line, trace):
|
def parse_parameters(line, trace):
|
||||||
|
@ -45,20 +45,20 @@ import sys
|
|||||||
|
|
||||||
def readDependencies(fname):
|
def readDependencies(fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
o = subprocess.Popen(['otool', '-L', fname], stdout=subprocess.PIPE)
|
with subprocess.Popen(['otool', '-L', fname], stdout=subprocess.PIPE) as o:
|
||||||
for line in o.stdout:
|
for line in o.stdout:
|
||||||
if line[0] == '\t':
|
if line[0] == '\t':
|
||||||
library = line.split(' ', 1)[0][1:]
|
library = line.split(' ', 1)[0][1:]
|
||||||
if (library.startswith("/usr/local/lib") or
|
if (library.startswith("/usr/local/lib") or
|
||||||
library.startswith("/usr/local/opt") or
|
library.startswith("/usr/local/opt") or
|
||||||
library.startswith("/Users/")):
|
library.startswith("/Users/")):
|
||||||
if (os.path.basename(library) != os.path.basename(fname)):
|
if (os.path.basename(library) != os.path.basename(fname)):
|
||||||
command = "install_name_tool -change " + \
|
command = "install_name_tool -change " + \
|
||||||
library + " @executable_path/./" + \
|
library + " @executable_path/./" + \
|
||||||
os.path.basename(library) + " " + fname
|
os.path.basename(library) + " " + fname
|
||||||
print(command)
|
print(command)
|
||||||
os.system("chmod +w " + fname)
|
os.system("chmod +w " + fname)
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
|
||||||
root = sys.argv[1]
|
root = sys.argv[1]
|
||||||
for (dirpath, dirnames, filenames) in os.walk(root):
|
for (dirpath, dirnames, filenames) in os.walk(root):
|
||||||
|
@ -67,13 +67,13 @@ class regressor():
|
|||||||
if not env:
|
if not env:
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
|
||||||
logfh = open(logfile, 'w')
|
with open(logfile, 'w') as logfh:
|
||||||
proc = subprocess.Popen(command, shell=True, executable='/bin/bash',
|
with subprocess.Popen(command, shell=True, executable='/bin/bash',
|
||||||
env=env, stdout=logfh,
|
env=env, stdout=logfh,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT) as proc:
|
||||||
ret = proc.wait()
|
ret = proc.wait()
|
||||||
logfh.close()
|
logfh.close()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def process_log(self, logfile):
|
def process_log(self, logfile):
|
||||||
"""
|
"""
|
||||||
|
@ -42,19 +42,19 @@ def writeSourceToFile(lines):
|
|||||||
# print("filePath is", filePath)
|
# print("filePath is", filePath)
|
||||||
if filePath != False:
|
if filePath != False:
|
||||||
os.system("mkdir -p " + filePath)
|
os.system("mkdir -p " + filePath)
|
||||||
f = open(srcName, mode='a+', encoding='utf8', newline='')
|
with open(srcName, mode='a+', encoding='utf8', newline='') as f:
|
||||||
createdSources.append(srcName)
|
createdSources.append(srcName)
|
||||||
i = 0
|
i = 0
|
||||||
for idx, line in enumerate(lines[1:]):
|
for idx, line in enumerate(lines[1:]):
|
||||||
|
|
||||||
# write to file
|
# write to file
|
||||||
if line[:12] != "==== Source:":
|
if line[:12] != "==== Source:":
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
# recursive call if there is another source
|
# recursive call if there is another source
|
||||||
else:
|
else:
|
||||||
writeSourceToFile(lines[1+idx:])
|
writeSourceToFile(lines[1+idx:])
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user