def test_graph_exception(): print(" Testing the graph_exception class/module.") prompt = " ... Test: Raise graph_exception {}" statistical_analysis.increment_number_test_cases_used() try (config_manager.get_result_repository() == "Unknown location."): print(prompt .format("OK")) statistical_analysis.increment_number_test_cases_passed()
def test_file_io_operations_open_file_object_write_results(): prompt = " Test: file_io_BLAH.open_file_object_write_results() {}" statistical_analysis.increment_number_test_cases_used() results_f_obj = file_io_operations.open_file_object_write_results() if results_f_obj: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) file_io_operations.close_file_object(results_f_obj)
def test_statistical_analysis(): print("1) Number of test cases passed: {}".format( statistical_analysis.number_test_cases_passed)) print("2) Number of test cases used: {}".format( statistical_analysis.number_test_cases_used)) for x in range(1, 7): statistical_analysis.increment_number_test_cases_used() statistical_analysis.increment_number_test_cases_passed() print("Value of x is: {}.".format(x)) print("Number of test cases passed: {}".format( statistical_analysis.number_test_cases_passed)) print("Number of test cases used: {}".format( statistical_analysis.number_test_cases_used))
def test_is_valid_month(): print(" Testing date_time_operations.is_valid_month() method.") prompt = " ... Test: month = 0 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_month(0): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: month = -7 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_month(-7): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: month > 12 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_month(15): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: month = 10 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_month(10): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_is_valid_year(): print(" Testing date_time_operations.is_valid_year() method.") prompt = " ... Test: year < 2014 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_year(2010): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: year = -467 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_year(-467): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: year > 3645 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_year(3645): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: year = 2019 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_year(2019): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_file_io_operations_check_file_extension(): 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!!!"))
def test_file_io_operations_on_files_with_same_content(): 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()
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_on_files_with_same_content(): 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( "dev-notes/run_regression_testing-original-copy.py", "dev-notes/run_regression_testing-same-copy.py"): 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( "dev-notes/run_regression_testing-original-copy.py", "dev-notes/run_regression_testing-different-copy.py"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed()
def test_file_io_operations_get_file_extension(): 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!!!"))
def test_date_time_tokenization(): print(" Testing date & time tokenization method.") # Number of tokens in the DD-MM-YY-HR-MN-SS-US format. number_of_tokens = 7 prompt = " ... Test: invalid DD-MM-YY-HR-MN-SS-US format {}" statistical_analysis.increment_number_test_cases_used() tokens = date_time_operations.get_date_time_tokens_of_filename( "12-2018-14-11-50-912982.invalid") if (None != tokens) and (number_of_tokens == len(tokens)): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: with None object {}" statistical_analysis.increment_number_test_cases_used() tokens = None if (None != tokens) and (number_of_tokens == len(tokens)): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: valid DD-MM-YY-HR-MN-SS-US format {}" statistical_analysis.increment_number_test_cases_used() tokens = date_time_operations.get_date_time_tokens_of_filename( generate_filename.create_filename()) if (None != tokens) and (number_of_tokens == len(tokens)): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_is_valid_30_day_month(): print(" Testing date_time_operations.is_valid_30_day_month() method.") prompt = " ... Test: not 30-day month, mm = 2 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_30_day_month(17, 2): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: not 30-day month, mm = 12 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_30_day_month(17, 12): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 30-day month, dd < 0 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_30_day_month(-8, 6): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 30-day month, dd = 0 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_30_day_month(0, 4): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 30-day month, dd = 27 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_30_day_month(27, 11): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
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")
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_find_desired_location_for_results(): incorrect_format_result = "'filename' needs to have the format: DD-MM-YY-HH-MM-SS-uS.txt." print("== Test: test_find_desired_location_for_results().") test_filename = "25-3-2010-5-8-51-9994073289.dwq" results_location = misc.find_desired_location_for_results( test_filename) prompt = " ... Test: filename is 25-3-2010-5-8-51-9994073289.dwq. {}" statistical_analysis.increment_number_test_cases_used() if misc.find_desired_location_for_results( test_filename) == incorrect_format_result: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print("== Test: test_find_desired_location_for_results().") test_filename = "25-3-2010-5-8-51-9407.txt" results_location = misc.find_desired_location_for_results( test_filename) prompt = " ... Test: filename 25-3-2010-5-8-51-9407.txt included. {}" statistical_analysis.increment_number_test_cases_used() if misc.check_absolute_path_to_store_results(results_location, test_filename): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 25-3-2010-5-8-51-9407.txt, correct path. {}" statistical_analysis.increment_number_test_cases_used() if misc.get_absolute_path_to_store_results() in results_location: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) """ print("results_location:",results_location,"=") print("misc.get_absolute_path_to_store_results():",misc.get_absolute_path_to_store_results(),"=") print(results_location.find(misc.get_absolute_path_to_store_results())) """ f_obj = misc.store_results(results_location) f_obj.write( "Storage of experimental, simulation, verification, and testing results work." ) file_io_operations.close_file_object(f_obj)
def test_is_valid_date_in_Feb(): print(" Testing date_time_operations.is_valid_date_in_Feb() method.") prompt = " ... Test: not February, mm = 12 {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_date_in_Feb(17, 12, 2016): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: not February, mm = -2 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date_in_Feb(17, -2, 2016): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: not February, mm = 14 {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date_in_Feb(17, 14, 2016): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_time_operations(): print("== Testing class: date_time_operations.") print(" Testing date_time_operations.is_valid_time() method.") prompt = " ... Test: single error, hh {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(34, 5, 3, 124395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(4, -8215, 3, 124395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, ss {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(4, 15, 586, 124395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, us {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(4, 15, 56, 123435435434395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: double errors, ss and us {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(4, 15, 956, 123435435434395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: multiple errors, hh, ss, and us {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_time(42390534, 15, 956, 123435435434395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: no error {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_time(23, 59, 59, 124395): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: no error {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_time(0, 0, 0, 000000): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: no error {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_time(1, 1, 1, 1): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
statistical_analysis.increment_number_test_cases_passed() except graph_exception: print(prompt .format("FAIL!!!")) #print("location=",config_manager.get_result_repository(),"=") except: print(prompt .format("FAIL fail!!!")) absolute_path = "/Users/zhiyang/Documents/ricerca/risultati_sperimentali/std-cell-library-characterization" prompt = " ... Test: result_repository, check change to abs. path. {}" statistical_analysis.increment_number_test_cases_used() if config_manager.set_result_repository(absolute_path): print(" result_repository is changed to an absolute path.") else: print(" result_repository is NOT changed to an absolute path.") if (config_manager.get_result_repository() == absolute_path): print(prompt .format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt .format("FAIL!!!")) print("Actual location=",config_manager.get_result_repository(),"=") # ------------------------------------------------------------ prompt = " ... Test: result_repository, check change to rel. path. {}" statistical_analysis.increment_number_test_cases_used() """ Set "result_repository" to a relative path that is equivalent absolute path, "absolute_path". """ if config_manager.set_result_repository("~/Documents/ricerca/risultati_sperimentali/std-cell-library-characterization"): print(" result_repository is changed to an relative path.") else: print(" result_repository is NOT changed to an relative path.") """
def test_configure_sw_application_parameters(): print(" Testing the config_manager class/module.") prompt = " ... Test: check default result_repository {}" statistical_analysis.increment_number_test_cases_used() if (config_manager.get_result_repository() == "Unknown location."): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) absolute_path = "/Users/zhiyang/Documents/ricerca/risultati_sperimentali/std-cell-library-characterization" prompt = " ... Test: result_repository, check change to abs. path. {}" statistical_analysis.increment_number_test_cases_used() if config_manager.set_result_repository(absolute_path): print(" result_repository is changed to an absolute path.") else: print(" result_repository is NOT changed to an absolute path.") if (config_manager.get_result_repository() == absolute_path): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print("Actual location=", config_manager.get_result_repository(), "=") # ------------------------------------------------------------ prompt = " ... Test: result_repository, check change to rel. path. {}" statistical_analysis.increment_number_test_cases_used() """ Set "result_repository" to a relative path that is equivalent absolute path, "absolute_path". """ if config_manager.set_result_repository( "~/Documents/ricerca/risultati_sperimentali/std-cell-library-characterization" ): print(" result_repository is changed to an relative path.") else: print(" result_repository is NOT changed to an relative path.") """ "result_repository" is changed to an relative path. However, compare "result_repository" to the equivalent absolute path. This is because if a relative path is detected, it will be transform/changed to an absolute path, before being assigned to "result_repository". """ if (config_manager.get_result_repository() == absolute_path): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print("Actual location=", config_manager.get_result_repository(), "=") # ------------------------------------------------------------ prompt = " ... Test: result_repository, changing to invalid path. {}" statistical_analysis.increment_number_test_cases_used() """ Set "result_repository" to an invalid path. """ if not config_manager.set_result_repository( "~/This/is/an/invalid/path"): print(" result_repository is not changed to an invalid path.") else: print(" result_repository is CHANGED to an INVALID path.") """ "result_repository" should not be changed to an invalid path. Hence, it shall still refer to "absolute_path". """ if (config_manager.get_result_repository() == absolute_path): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print("Actual location=", config_manager.get_result_repository(), "=")
def test_check_filename_format(): print(" Testing the filename format checker.") prompt = " ... Test: incorrect file extension is '.txt'. {}" statistical_analysis.increment_number_test_cases_used() if misc.check_filename_format("tyuw.iew"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename no file extension has 6 tokens. {}" statistical_analysis.increment_number_test_cases_used() if misc.check_filename_format("HH-MM-SS-uS.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with -ve DD/day. {}" statistical_analysis.increment_number_test_cases_used() if misc.check_filename_format("-5-MM-YY-HH-MM-SS-uS.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with DD/day >29, Feb. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("35-2-2016-00-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with DD/day=29, Feb, leap year. {}" statistical_analysis.increment_number_test_cases_used() if misc.check_filename_format("29-2-2016-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with DD/day=28, Feb, not leap year. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("28-2-2017-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with DD/day = 34. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("34-6-2017-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with DD/day=31, 31 day mth. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("31-7-2017-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with DD/day=30, 30 day mth. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-9-2017-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with MM/month = 0. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-0-2017-00-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with MM/month = -4. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30--4-2017-00-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with MM/month = 15. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-15-2017-00-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with MM/month = 9. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-9-2017-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with YY/year = 1582. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-11-1582-00-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with YY/year = 2083. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("2-2-2083-00-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with HH/hour = -3. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("30-5-2015--3-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with HH/hour = 25. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("3-5-2017-25-00-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with HH/hour = 17. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("12-1-2013-17-00-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with MM/minute = -8. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("7-4-2012-2--8-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with MM/minute = 73. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-73-00-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with MM/minute = 59. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-59-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with MM/minute = 0. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-0-00-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with SS/second = -4. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8--4-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with SS/second = 81. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-81-00.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with SS/second = 36. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-36-00.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with uS/microsecond = -129. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-4--129.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with uS/microsecond = 16534785929. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-32-16534785929.txt"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: filename with uS/microsecond = 0. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-32-0.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: filename with uS/microsecond = 999999. {}" statistical_analysis.increment_number_test_cases_used() """ All fields/tokens need to be numbers, else an exception would be thrown. """ if misc.check_filename_format("25-1-2020-5-8-51-999999.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
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!!!"))
def test_if_help_needed(): print(" Testing for no help needed...") # Set the list of input arguments to have 2 arguments. name_of_script_dumped = "name-of-the-script" current_1st_ip_arg = "garbage.json" current_2nd_ip_arg = "nonsense.json" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) prompt8 = " ... Test: queue_ip_args.check_if_help_wanted() {}" statistical_analysis.increment_number_test_cases_used() queue_ip_args.check_if_help_wanted() print(prompt8.format(" OK")) statistical_analysis.increment_number_test_cases_passed() print(" Testing for help needed (1st arg)... ") # Change the list of input arguments to have "-h" option. current_1st_ip_arg = "-h" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) statistical_analysis.increment_number_test_cases_used() try: queue_ip_args.check_if_help_wanted() print(prompt8.format("FAIL!!!")) except: print(prompt8.format(" OK")) statistical_analysis.increment_number_test_cases_passed() print(" Testing for help needed (2nd arg)... ") current_1st_ip_arg = "garbage.json" current_2nd_ip_arg = "-h" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) statistical_analysis.increment_number_test_cases_used() try: queue_ip_args.check_if_help_wanted() print(prompt8.format("FAIL!!!")) except: print(prompt8.format(" OK")) statistical_analysis.increment_number_test_cases_passed() print(" Testing for help needed (3rd arg)... ") current_1st_ip_arg = "garbage.json" current_2nd_ip_arg = "nonsense.json" current_3rd_ip_arg = "-h" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg, current_3rd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) statistical_analysis.increment_number_test_cases_used() try: queue_ip_args.check_if_help_wanted() print(prompt8.format("FAIL!!!")) except: print(prompt8.format(" OK")) statistical_analysis.increment_number_test_cases_passed()
def test_processing_input_arguments(): print(" Test: queue_ip_args.process_1st_ip_arg()... ") name_of_script_dumped = "name-of-the-script" current_1st_ip_arg = "garbage.json" current_2nd_ip_arg = "notes/guidelines/guidelines.tex" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) prompt9 = " ... Invalid path to file {}" statistical_analysis.increment_number_test_cases_used() try: ip_fname = queue_ip_args.process_1st_ip_arg() print(prompt9.format(" FAIL!!!")) except: print(prompt9.format(" OK")) statistical_analysis.increment_number_test_cases_passed() # - - - - - - - - - - - - - """ 1st input argument: Valid path to file, no JSON file extension. """ #current_1st_ip_arg = "benchmarks/majority_netlist.json" current_1st_ip_arg = "notes/mit-license.text" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] queue_ip_args.set_input_arguments(new_list_ip_args) prompt10 = " ... Valid path to file, no JSON file extension. {}" statistical_analysis.increment_number_test_cases_used() try: ip_fname = queue_ip_args.process_1st_ip_arg() print(prompt10.format(" FAIL!!!")) except: print(prompt10.format(" OK")) statistical_analysis.increment_number_test_cases_passed() """ 1st input argument: Valid path to file, JSON file extension. """ current_1st_ip_arg = "benchmarks/majority_netlist.json" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] queue_ip_args.set_input_arguments(new_list_ip_args) prompt10 = " ... Valid path to file, JSON file extension. {}" statistical_analysis.increment_number_test_cases_used() ip_fname = queue_ip_args.process_1st_ip_arg() print(prompt10.format(" OK")) statistical_analysis.increment_number_test_cases_passed() print(" - - - - - - - -") print(" Test: queue_ip_args.process_2nd_ip_arg()... ") prompt11 = " ... Valid path to file {}" statistical_analysis.increment_number_test_cases_used() try: op_fname = queue_ip_args.process_2nd_ip_arg() print(prompt11.format(" FAIL!!!")) except: print(prompt11.format(" OK")) statistical_analysis.increment_number_test_cases_passed() prompt12 = " ... Invalid path to file, no JSON extension {}" statistical_analysis.increment_number_test_cases_used() current_2nd_ip_arg = "nonsense" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] queue_ip_args.set_input_arguments(new_list_ip_args) try: op_fname = queue_ip_args.process_2nd_ip_arg() print(prompt12.format(" OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt12.format(" FAIL!!!")) prompt13 = " ... Invalid path to file, JSON extension {}" statistical_analysis.increment_number_test_cases_used() current_2nd_ip_arg = "nonsense.json" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] queue_ip_args.set_input_arguments(new_list_ip_args) try: op_fname = queue_ip_args.process_2nd_ip_arg() print(prompt13.format(" OK")) statistical_analysis.increment_number_test_cases_passed() except: print(prompt13.format(" FAIL!!!"))
def test_o1_methods(): print(" Test: queue_ip_args.how_to_use_script() OK") queue_ip_args.how_to_use_script() statistical_analysis.increment_number_test_cases_used() statistical_analysis.increment_number_test_cases_passed() print(" Test: queue_ip_args.print_help_option() OK") queue_ip_args.print_help_option() statistical_analysis.increment_number_test_cases_used() statistical_analysis.increment_number_test_cases_passed() print(" Test: queue_ip_args.get_list_of_input_arguments() OK") temp_set_ip_args = queue_ip_args.get_list_of_input_arguments() statistical_analysis.increment_number_test_cases_used() statistical_analysis.increment_number_test_cases_passed() # - - - - - - - - - - - - - - - print(" Test: queue_ip_args.print_all_input_arguments() OK") queue_ip_args.print_all_input_arguments() statistical_analysis.increment_number_test_cases_used() statistical_analysis.increment_number_test_cases_passed() # - - - - - - - - - - - - - - - prompt = " Test: queue_ip_args.get_1st_input_argument() {}" statistical_analysis.increment_number_test_cases_used() if queue_ip_args.get_1st_input_argument() is not None: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) # - - - - - - - - - - - - - - - prompt = " Test: queue_ip_args.get_2nd_input_argument() {}" statistical_analysis.increment_number_test_cases_used() if queue_ip_args.get_2nd_input_argument() is not None: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) # - - - - - - - - - - - - - - - print(" Testing for an empty list...") prompt1 = " ... Test: queue_ip_args.get_list_of_input_arguments() {}" statistical_analysis.increment_number_test_cases_used() prompt2 = " ... Test: queue_ip_args.get_number_of_input_arguments() {}" statistical_analysis.increment_number_test_cases_used() prompt4 = " ... Test: queue_ip_args.set_input_arguments(...) {}" statistical_analysis.increment_number_test_cases_used() prompt5 = " ... Test: queue_ip_args.get_1st_input_argument() {}" prompt6 = " ... Test: queue_ip_args.get_2nd_input_argument() {}" # List of input arguments. old_list_ip_args = queue_ip_args.get_list_of_input_arguments() new_list_ip_args = [] """ Assign input arguments to "set_input_arguments(...)" for processing. Statement should fail. """ try: queue_ip_args.set_input_arguments(new_list_ip_args) except: if old_list_ip_args == queue_ip_args.get_list_of_input_arguments(): print(prompt1.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt1.format("FAIL!!!")) #print(queue_ip_args.get_list_of_input_arguments()) if len(old_list_ip_args ) == queue_ip_args.get_number_of_input_arguments(): print(prompt2.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt2.format("FAIL!!!")) #print(queue_ip_args.get_number_of_input_arguments()) print(prompt4.format("OK")) statistical_analysis.increment_number_test_cases_passed() print(" Testing for list with 1 argument...") """ Set the list of input arguments to have 1 argument, in addition to the name of the script. Hence, the list would have 2 arguments, since the first "argument" is dumped during the method call to set_input_arguments(...); this first "argument" is the name of the currently executing script. """ name_of_script_dumped = "name-of-the-script" current_1st_ip_arg = "benchmarks/majority_netlist.json" new_list_ip_args = [name_of_script_dumped, current_1st_ip_arg] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) statistical_analysis.increment_number_test_cases_used() if new_list_ip_args == queue_ip_args.get_list_of_input_arguments(): print(prompt1.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt1.format("FAIL!!!")) #print(queue_ip_args.get_list_of_input_arguments()) statistical_analysis.increment_number_test_cases_used() if len(new_list_ip_args ) == queue_ip_args.get_number_of_input_arguments(): print(prompt2.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt2.format("FAIL!!!")) #print(len(new_list_ip_args)-1) #print(queue_ip_args.get_number_of_input_arguments()) statistical_analysis.increment_number_test_cases_used() print(prompt4.format("OK")) statistical_analysis.increment_number_test_cases_passed() # - - - - - - - - - - - - - - statistical_analysis.increment_number_test_cases_used() if current_1st_ip_arg == queue_ip_args.get_1st_input_argument(): print(prompt5.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt5.format("FAIL!!!")) """ If an input argument for the software is "-h", show the brief user manual to the user. Else, there is no need to test for more than 2 input arguments for the software, since only the first two are processed. So, the list shall have 3 elements, since the first element is dumped during the method call to set_input_arguments(...). """ print(" Testing for list with 2 arguments...") # Set the list of input arguments to have 2 arguments. #new_list_ip_args = ["benchmarks/majority_netlist.json" "nonsense.json"] current_1st_ip_arg = "garbage.json" current_2nd_ip_arg = "nonsense.json" new_list_ip_args = [ name_of_script_dumped, current_1st_ip_arg, current_2nd_ip_arg ] # Assign input arguments to "set_input_arguments(...)" for processing. queue_ip_args.set_input_arguments(new_list_ip_args) statistical_analysis.increment_number_test_cases_used() if new_list_ip_args == queue_ip_args.get_list_of_input_arguments(): print(prompt1.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt1.format("FAIL!!!")) #print(queue_ip_args.get_list_of_input_arguments()) statistical_analysis.increment_number_test_cases_used() if len(new_list_ip_args ) == queue_ip_args.get_number_of_input_arguments(): print(prompt2.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt2.format("FAIL!!!")) #print(queue_ip_args.get_number_of_input_arguments()) statistical_analysis.increment_number_test_cases_used() print(prompt4.format("OK")) statistical_analysis.increment_number_test_cases_passed() # - - - - - - - - - - - - - - statistical_analysis.increment_number_test_cases_used() if current_2nd_ip_arg == queue_ip_args.get_2nd_input_argument(): print(prompt6.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt6.format("FAIL!!!")) prompt7 = " ... Test: queue_ip_args.input_arguments_error() {}" statistical_analysis.increment_number_test_cases_used() try: queue_ip_args.input_arguments_error() print(prompt7.format("FAIL!!!")) except: print(prompt7.format(" OK")) statistical_analysis.increment_number_test_cases_passed()
def check_filename_format(): print(" Generate a filename with the current time stamp.") temp_op_filename = generate_filename.create_filename() print(" Testing filename:", temp_op_filename, "=") print(" Check against the format: DD-MM-YY-HH-MM-SS-uS.txt") # https://stackoverflow.com/questions/678236/how-to-get-the-filename-without-the-extension-from-a-path-in-python temp_op_filename_wo_extn, file_extn = os.path.splitext( temp_op_filename) print(" Testing if the filename has the correct file extension.") prompt = " ... Test: file extension is '.txt'. {}" statistical_analysis.increment_number_test_cases_used() if ".txt" == file_extn: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing if filename without file extension has right format.") # Tokenize the generated filename with the delimiter "-". tokens = temp_op_filename_wo_extn.split("-") """ Check against the format: DD-MM-YY-HH-MM-SS-uS[.txt]. tokens[0] = DD/Day tokens[1] = MM/Month tokens[2] = YY/Year tokens[3] = HH/Hour tokens[4] = MM/Minute tokens[5] = [SS/Second] tokens[6] = [uS/Microsecond] """ prompt = " ... Test: filename format is DD-MM-YY-HH-MM-SS-uS. {}" statistical_analysis.increment_number_test_cases_used() if 7 == len(tokens): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(tokens) print(" Tokenize generated filename.") print(" Testing if 1st token is appropriate date (DD/date value).") prompt = " ... Test: DD value is >= 0. {}" statistical_analysis.increment_number_test_cases_used() if 1 <= int(tokens[0]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) # If month is February during a leap year, DD <= 29. prompt = " ... Test: DD value is <= 29, leap year Feb. {}" statistical_analysis.increment_number_test_cases_used() if 2 == int(tokens[1]) and 29 < int(tokens[0]) and calendar.isleap( int(tokens[2])): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # If year isn't a leap year & month is February, DD <= 28. prompt = " ... Test: DD value is <= 28, non-leap year Feb. {}" statistical_analysis.increment_number_test_cases_used() if 2 == int(tokens[1]) and 28 < int(tokens[0]) and not calendar.isleap( int(tokens[2])): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: DD value is <= 30, 30-day month. {}" statistical_analysis.increment_number_test_cases_used() if generate_filename_tester.is_30_day_month( tokens[1]) and 30 < int(tokens[0]): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: DD value is <= 31, 31-day month. {}" statistical_analysis.increment_number_test_cases_used() if generate_filename_tester.is_31_day_month( tokens[1]) and 31 < int(tokens[0]): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() print(" Testing if 2nd token is appropriate date (MM/month value).") prompt = " ... Test: MM/month value is >= 1. {}" statistical_analysis.increment_number_test_cases_used() if 1 <= int(tokens[1]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: MM/month value is <= 12. {}" statistical_analysis.increment_number_test_cases_used() if 12 >= int(tokens[1]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing if 3rd token is appropriate date (YY/year value).") prompt = " ... Test: YY/year value is >= 2000. {}" statistical_analysis.increment_number_test_cases_used() if 2000 <= int(tokens[2]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing if 4th token is appropriate date (HH/hour value).") prompt = " ... Test: HH/hour value is >= 0. {}" statistical_analysis.increment_number_test_cases_used() if 0 <= int(tokens[3]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: HH/hour value is <= 23. {}" statistical_analysis.increment_number_test_cases_used() if 23 >= int(tokens[3]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing if 5th token is appropriate date (MM/minute value).") prompt = " ... Test: MM/minute value is >= 0. {}" statistical_analysis.increment_number_test_cases_used() if 0 <= int(tokens[4]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: MM/minute value is <= 59. {}" statistical_analysis.increment_number_test_cases_used() if 59 >= int(tokens[4]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print(" Testing if 6th token is appropriate date (SS/second value).") prompt = " ... Test: SS/second value is >= 0. {}" statistical_analysis.increment_number_test_cases_used() if 0 <= int(tokens[5]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: SS/second is <= 59. {}" statistical_analysis.increment_number_test_cases_used() if 59 >= int(tokens[5]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) print( " Testing if 7th token is appropriate date (uS/microsecond value)." ) prompt = " ... Test: uS/microsecond value is >= 0. {}" statistical_analysis.increment_number_test_cases_used() if 0 <= int(tokens[6]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: uS/microsecond value is <= 999999. {}" statistical_analysis.increment_number_test_cases_used() if 999999 >= int(tokens[6]): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_date_operations(): print(" Testing date_time_operations.is_valid_date() method.") prompt = " ... Test: single error, dd {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(34, 5, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, -dd {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(-6701, 5, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(24, 15, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(6, 0, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, -mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(6, -20, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(6, 2, 6017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(6, 2, 1017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: double errors, dd and yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(29, 2, 2018): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: double errors, dd and yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(30, 2, 1980): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: double errors, dd and mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(31, 4, 2018): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: multiple errors, dd, mm, and yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.is_valid_date(32, -4, 1988): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: no error {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_date(31, 7, 2015): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: no error {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.is_valid_date(30, 6, 2017): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) # ----------------------------------------------------------------- print( " Testing date_time_operations.check_filename_date_time_format() method." ) prompt = " ... Test: single error, dd {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.check_filename_date_time_format( "54-9-2018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.check_filename_date_time_format( "54-9-3018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: single error, mm {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.check_filename_date_time_format( "29-82-2018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: multiple errors, dd, mm, yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.check_filename_date_time_format( "29-2-2018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: multiple errors, dd, mm, yy {}" statistical_analysis.increment_number_test_cases_used() if not date_time_operations.check_filename_date_time_format( "30-2-2016-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: valid date & time - leap year {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.check_filename_date_time_format( "29-2-2016-21-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: valid date & time {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.check_filename_date_time_format( "28-2-2018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: valid date & time {}" statistical_analysis.increment_number_test_cases_used() if date_time_operations.check_filename_date_time_format( "31-5-2018-13-58-59-734507.txt"): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))