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