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")
print("a is:",a,"=") a.clear() print("a is:",a,"=") 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"))
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!!!"))