def parse_configuration_file(): """ File object associated with reading the configuration file that parameterizes this software. """ config_file_obj = file_io_operations.open_file_object_read( config_parser.name_of_configuration_file) #print(" ... Created file object: config_file_obj.") temp_dictionary = json_obj(config_file_obj) #print("temp_dictionary:=",temp_dictionary,"=") #print("temp_dictionary.__list__=",temp_dictionary.__list__,"=") """ A 'json_obj' object with the ".__list__" suffix is subscriptable. Hence, I can use the name of a field in the JSON object to access the value of that field. """ #print("temp_dictionary.__list__['result_repository']=",temp_dictionary.__list__["result_repository"],"=") """ The temp_dictionary is not subscriptable, since 'json_obj' objects are not subscriptable. Hence, the following sentence is not valid. """ #print("temp_dictionary['result_repository']=",temp_dictionary["result_repository"],"=") #if config_manager.set_result_repository(temp_dictionary.__list__["output"]): if config_manager.set_result_repository( temp_dictionary.__list__["result_repository"]): return True else: return False
def preprocessing(): """ if ip_file_obj is not None: file_io_operations.close_file_object(ip_file_obj) if op_file_obj is not None: file_io_operations.close_file_object(op_file_obj) """ print("= Create a file object for reading and writing.") # Create a file object for input BibTeX file, in reading mode. mean_variance_estimator.ip_file_obj = file_io_operations.open_file_object_read( mean_variance_estimator.input_filename) mean_variance_estimator.op_file_obj = file_io_operations.open_file_object_write_new( mean_variance_estimator.output_filename)
def test_file_io_operations_with_invalid_file(): print(" ... Testing file operations with invalid file.") filename = "nonsense" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if not file_io_operations.is_path_valid(filename): print(prompt.format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt.format("FAIL!!!")) except: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) prompt = " Test: file_io_ops[BLAH].open_file_object_write_new(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write_new(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) try: # Close the file object, and delete the file. statistical_analysis.increment_number_test_cases_used() file_io_operations.close_file_object(f_obj) os.remove(filename) print(" Test: file_io_operations.close_file_object(...) OK") statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!"))
def test_file_io_operations_with_valid_file(): print(" ... Testing file operations with valid file.") filename = "notes/mit-license-original-copy.text" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.is_path_valid(filename): print(prompt.format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write( file_io_operations.result_repository, file_io_operations.results_suffix) print(prompt.format("FAIL!!!")) except: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " Test: file_io_ops[BLAH].open_file_object_write_new(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write_new( "mit-license-write-new-copy.text") print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) """ Close the file object to preserve data in the test data file. filename = "notes/mit-license.text" """ file_io_operations.close_file_object(f_obj)
def test_file_io_operations_with_valid_file(): print(" ... Testing file operations with valid file.") filename = "dev-notes/run_regression_testing.py" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.is_path_valid(filename): print(prompt.format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write( "run_regression_testing-write-copy.py") print(prompt.format("FAIL!!!")) except: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " Test: file_io_ops[BLAH].open_file_object_write_new(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write_new( "run_regression_testing-write-new-copy.py") print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) """ Close the file object to preserve data in the test data file. filename = "dev-notes/run_regression_testing.py" """ file_io_operations.close_file_object(f_obj)
def test_file_io_operations_with_valid_file(): print(" ... Testing file operations with valid file.") filename = "notes/mit-license.text" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.is_path_valid(filename): print(prompt .format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt .format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt .format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt .format("FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write(filename) print(prompt .format("FAIL!!!")) except: print(prompt .format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " Test: file_io_ops[BLAH].open_file_object_write_new(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write_new(filename) print(prompt .format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt .format("FAIL!!!")) """ Close the file object to preserve data in the test data file. filename = "notes/mit-license.text" """ file_io_operations.close_file_object(f_obj) # Copy a file from [source] to [destination] copyfile("notes/trash/mit-license-spare-copy.text","notes/mit-license.text")
b = dict() print("b is:",b,"=") if a==b: print("a is equal to b.") Congleton2017_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/Congleton2017.json" WikipediaContributors2018p_1_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-1.json" WikipediaContributors2018p_2_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-2.json" WikipediaContributors2018p_3_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-3.json" WikipediaContributors2018p_4_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-4.json" # Parsing JSON files \cite{Congleton2017}. if file_io_operations.is_path_valid(Congleton2017_json): print("= Start parsing Congleton2017_json.") # Create a file object to read the file Congleton2017_json. Congleton2017_json_fo = file_io_operations.open_file_object_read(Congleton2017_json) # Load the JSON file (object) into a dictionary. Congleton2017_json_dict = json.load(Congleton2017_json_fo) print("= Print the entire Congleton2017_json_dict.") print(Congleton2017_json_dict) print("= For each dictionary in Congleton2017_json_dict, print its name field.") for dict in Congleton2017_json_dict: print(dict['Name']) print("= Close the file objects.") file_io_operations.close_file_object(Congleton2017_json_fo) print("= Learning about transforming relative paths.") print(os.path.expanduser("~/Documents/ricerca")) print(os.path.expanduser("~/this/is/nonsense")) print(os.path.expanduser("../../")) print(os.path.expanduser("statistics/__pycache__/"))
"==================================================") regression_results_f_obj.write( "Automating incremental regression testing of my software") regression_results_f_obj.write(" solution for genetic technology mapping.") regression_results_f_obj.write("") # Assign input arguments to "queue_ip_args" for processing. #queue_ip_args.set_input_arguments(sys.argv,queue_ip_args.INCREMENTAL_TEST) queue_ip_args.set_input_arguments(sys.argv) # Check if user wants to read the brief user manual. queue_ip_args.check_if_help_wanted() # Process the first input argument. regression_results_f_obj.write("= Process the first input argument.") ip_filename = queue_ip_args.process_1st_ip_arg() regression_results_f_obj.write("= Create a file object for reading.") # Create a file object for input BibTeX file, in reading mode. ip_file_obj = file_io_operations.open_file_object_read(ip_filename) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # The real stuff begins here... regression_results_f_obj.write("- - - - - - - - - - - - -") regression_results_f_obj.write( "= Testing the statistical analysis package.") # Insert test cases for statistical analysis package statistical_analysis_tester.test_statistical_analysis( regression_results_f_obj) # Test module performing operations on basic data types & numbers. data_type_n_number_ops_tester.test_data_type_n_number_ops( regression_results_f_obj) # Test the miscellaneous tasks in analyzing data. data_analysis_tester.test_data_analysis() regression_results_f_obj.write("") regression_results_f_obj.write("- - - - - - - - - - - - -")
def test_json_object_accessibility(): # List of JSON files to test JSON-to-Python transformation. Congleton2017_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/Congleton2017.json" WikipediaContributors2018p_1_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-1.json" WikipediaContributors2018p_2_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-2.json" WikipediaContributors2018p_3_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-3.json" WikipediaContributors2018p_4_json = "/Users/zhiyang/Documents/ricerca/gulyas-scripts/sandbox/python/json-files/WikipediaContributors2018p-4.json" # ------------------------------------------------------- print(" ... Test transformation of JSON objects to Python objects.") prompt = " Test: Congleton2017_json {}" statistical_analysis.increment_number_test_cases_used() Congleton2017_json_fo = file_io_operations.open_file_object_read( Congleton2017_json) json_to_py_obj = json_obj(Congleton2017_json_fo) #print("= Print the transformed JSON object.") #print(json_to_py_obj.__dict__) #print("= Print the transformed JSON object: list format.") #print(json_to_py_obj.__list__) #print("= Print the loaded JSON object.") # Why does this line work, and the next line doesn't? Congleton2017_json_dict = json.load( file_io_operations.open_file_object_read(Congleton2017_json)) #Congleton2017_json_dict = json.load(Congleton2017_json_fo) #print(Congleton2017_json_dict) """ Compare contents of the Python Object with that from the json.load() operation. """ if json_to_py_obj.__list__ == Congleton2017_json_dict: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object(Congleton2017_json_fo) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - prompt = " Test: WikipediaContributors2018p_1_json {}" statistical_analysis.increment_number_test_cases_used() WikipediaContributors2018p_1_json_fo_1 = file_io_operations.open_file_object_read( WikipediaContributors2018p_1_json) WikipediaContributors2018p_1_json_fo_2 = file_io_operations.open_file_object_read( WikipediaContributors2018p_1_json) json_to_py_obj = json_obj(WikipediaContributors2018p_1_json_fo_1) WikipediaContributors2018p_1_json_dict = json.load( WikipediaContributors2018p_1_json_fo_2) """ Compare contents of the Python Object with that from the json.load() operation. """ if json_to_py_obj.__list__ == WikipediaContributors2018p_1_json_dict: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object( WikipediaContributors2018p_1_json_fo_1) file_io_operations.close_file_object( WikipediaContributors2018p_1_json_fo_2) """ This indicates that when a file object is created for a JSON load operation, it cannot be used for another JSON load operation. If I try to use a file object for multiple JSON load operations, a run-time json.decoder.JSONDecodeError will occur. """ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - prompt = " Test: WikipediaContributors2018p_2_json {}" statistical_analysis.increment_number_test_cases_used() WikipediaContributors2018p_2_json_fo_1 = file_io_operations.open_file_object_read( WikipediaContributors2018p_2_json) WikipediaContributors2018p_2_json_fo_2 = file_io_operations.open_file_object_read( WikipediaContributors2018p_2_json) json_to_py_obj = json_obj(WikipediaContributors2018p_2_json_fo_1) WikipediaContributors2018p_2_json_dict = json.load( WikipediaContributors2018p_2_json_fo_2) """ Compare contents of the Python Object with that from the json.load() operation. """ if json_to_py_obj.__list__ == WikipediaContributors2018p_2_json_dict: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object( WikipediaContributors2018p_2_json_fo_1) file_io_operations.close_file_object( WikipediaContributors2018p_2_json_fo_2) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - prompt = " Test: WikipediaContributors2018p_3_json {}" statistical_analysis.increment_number_test_cases_used() WikipediaContributors2018p_3_json_fo_1 = file_io_operations.open_file_object_read( WikipediaContributors2018p_3_json) WikipediaContributors2018p_3_json_fo_2 = file_io_operations.open_file_object_read( WikipediaContributors2018p_3_json) json_to_py_obj = json_obj(WikipediaContributors2018p_3_json_fo_1) WikipediaContributors2018p_3_json_dict = json.load( WikipediaContributors2018p_3_json_fo_2) """ Compare contents of the Python Object with that from the json.load() operation. """ if json_to_py_obj.__list__ == WikipediaContributors2018p_3_json_dict: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object( WikipediaContributors2018p_3_json_fo_1) file_io_operations.close_file_object( WikipediaContributors2018p_3_json_fo_2) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - prompt = " Test: WikipediaContributors2018p_4_json {}" statistical_analysis.increment_number_test_cases_used() WikipediaContributors2018p_4_json_fo_1 = file_io_operations.open_file_object_read( WikipediaContributors2018p_4_json) WikipediaContributors2018p_4_json_fo_2 = file_io_operations.open_file_object_read( WikipediaContributors2018p_4_json) json_to_py_obj = json_obj(WikipediaContributors2018p_4_json_fo_1) WikipediaContributors2018p_4_json_dict = json.load( WikipediaContributors2018p_4_json_fo_2) """ Compare contents of the Python Object with that from the json.load() operation. """ if json_to_py_obj.__list__ == WikipediaContributors2018p_4_json_dict: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object( WikipediaContributors2018p_4_json_fo_1) file_io_operations.close_file_object( WikipediaContributors2018p_4_json_fo_2)
def test_file_io_operations(): print("== Testing class: file_io_operations.") print(" ... Testing file operations with invalid file.") filename = "nonsense" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if not file_io_operations.is_path_valid(filename): print(prompt.format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt.format("FAIL!!!")) except: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) try: # Close the file object, and delete the file. statistical_analysis.increment_number_test_cases_used() file_io_operations.close_file_object(f_obj) os.remove(filename) print(" Test: file_io_operations.close_file_object(...) OK") statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) # ----------------------------------------------------------------- print(" ... Testing file operations with valid file.") filename = "notes/mit-license.text" prompt = " Test: file_io_operations.is_path_valid(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.is_path_valid(filename): print(prompt.format(" OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format(" FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_read(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_read(filename) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt.format("FAIL!!!")) prompt = " Test: file_io_operations.open_file_object_write(...) {}" statistical_analysis.increment_number_test_cases_used() try: f_obj = file_io_operations.open_file_object_write(filename) print(prompt.format("FAIL!!!")) except: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # ----------------------------------------------------------------- print(" Testing file operations on files with the same content.") prompt = " ... Test: file_io_operations.file_comparison(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.file_comparison( "notes/mit-license.text", "notes/trash/mit-license-spare-copy.text"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing file operations on files with the different content.") prompt = " ... Test: file_io_operations.file_comparison(...) {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.file_comparison( "notes/mit-license.text", "notes/guidelines/guidelines.tex"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # ----------------------------------------------------------------- print(" Testing file_io_operations.get_file_extension() method.") prompt = " ... Test: one file extension {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.get_file_extension("something.text") == ".text": print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: double/dual file extensions {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.get_file_extension( "something.tar.gz") == ".tar.gz": print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) #print(file_io_operations.get_file_extension("something.tar.gz")) prompt = " ... Test: multiple file extensions {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.get_file_extension( "something.pdf.tar.gz") == ".pdf.tar.gz": print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) # ----------------------------------------------------------------- print(" Testing file_io_operations.check_file_extension() method.") prompt = " ... Test: same file extension {}" statistical_analysis.increment_number_test_cases_used() if file_io_operations.check_file_extension("something.text", ".text"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: different file extensions {}" statistical_analysis.increment_number_test_cases_used() if not file_io_operations.check_file_extension("something.tar.gz", ".rtsdtfyg"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))