def test_raising_graph_error(): print("") print("== Testing the graph_error class/module.") try: prompt = " ... Test: raise graph_error exception, 2 arguments {}" statistical_analysis.increment_number_test_cases_used() #raise graph_error("Can graph_error be caught") #raise utilities.custom_exceptions.graph_error("Can graph_error be caught") raise graph_error("Can graph_error be caught?", "gyou") #except utilities.custom_exceptions.graph_error: except graph_error: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) try: prompt = " ... Test: raise graph_error exception, 1 argument {}" statistical_analysis.increment_number_test_cases_used() #raise graph_error("Can graph_error be caught") #raise utilities.custom_exceptions.graph_error("Can graph_error be caught") raise graph_error("Can graph_error be caught?") #except utilities.custom_exceptions.graph_error: except graph_error: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
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_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_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( "notes/mit-license-exact-copy.text", "notes/mit-license-same-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-exact-copy.text", "notes/mit-license-different-copy.text"): print(prompt.format("FAIL!!!")) else: print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed()
def test_check_elapsed_time(): print(" Testing check_elapsed_time() method.") prompt = " ... Test: check_elapsed_time() works {}." statistical_analysis.increment_number_test_cases_used() with warnings.catch_warnings(record=True) as w: # Check if default elapsed time = 0, and triggers warning. execution_time_measurement.check_elapsed_time() print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: check_elapsed_time(-235435) works {}." statistical_analysis.increment_number_test_cases_used() with warnings.catch_warnings(record=True) as w: # Check if default elapsed time < 0, and triggers warning. execution_time_measurement.check_elapsed_time(-235435) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() prompt = " ... Test: check_elapsed_time(5678) works {}." statistical_analysis.increment_number_test_cases_used() """ Check if default elapsed time > 0, and does not trigger any warning. """ execution_time_measurement.check_elapsed_time(5678) 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_get_elapsed_time(): print(" Testing get_elapsed_time() method.") # Set initial time stamp. execution_time_measurement_no_ns.set_initial_timestamp("perf_counter") prompt = " ... Test: for perf_counter {}." statistical_analysis.increment_number_test_cases_used() elapsed_t = execution_time_measurement_no_ns.get_elapsed_time() execution_time_measurement_no_ns.check_elapsed_time(elapsed_t) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # Reset and set initial time stamp. execution_time_measurement_no_ns.reset_initial_timestamp() if execution_time_measurement_no_ns.invalid_timestamp != execution_time_measurement_no_ns.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") execution_time_measurement_no_ns.set_initial_timestamp("process_time") prompt = " ... Test: for process_time {}." statistical_analysis.increment_number_test_cases_used() elapsed_t = execution_time_measurement_no_ns.get_elapsed_time() execution_time_measurement_no_ns.check_elapsed_time(elapsed_t) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # Reset and set initial time stamp. execution_time_measurement_no_ns.reset_initial_timestamp() if execution_time_measurement_no_ns.invalid_timestamp != execution_time_measurement_no_ns.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") execution_time_measurement_no_ns.set_initial_timestamp("time") prompt = " ... Test: for time {}." statistical_analysis.increment_number_test_cases_used() elapsed_t = execution_time_measurement_no_ns.get_elapsed_time() execution_time_measurement_no_ns.check_elapsed_time(elapsed_t) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() # Reset and set initial time stamp. execution_time_measurement_no_ns.reset_initial_timestamp() if execution_time_measurement_no_ns.invalid_timestamp != execution_time_measurement_no_ns.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") execution_time_measurement_no_ns.set_initial_timestamp("monotonic") prompt = " ... Test: for monotonic {}." statistical_analysis.increment_number_test_cases_used() elapsed_t = execution_time_measurement_no_ns.get_elapsed_time() execution_time_measurement_no_ns.check_elapsed_time(elapsed_t) print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed()
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(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( "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_convert_time_in_seconds_to_DD_HH_MM_SS(): print(" Testing convert_time_in_seconds_to_DD_HH_MM_SS() method.") prompt = " ... Test: convert_time_in_seconds_...() = 0s {}." statistical_analysis.increment_number_test_cases_used() if "0:00:00" == str(execution_time_measurement. convert_time_in_seconds_to_DD_HH_MM_SS()): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: convert_time_in_seconds_...(32:17) = 32:17 {}." statistical_analysis.increment_number_test_cases_used() if "0:32:17" == str( execution_time_measurement. convert_time_in_seconds_to_DD_HH_MM_SS(32 * 60 + 17)): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: convert_time_in_seconds_...(15:51:09) is ok {}." statistical_analysis.increment_number_test_cases_used() if "15:51:09" == str( execution_time_measurement. convert_time_in_seconds_to_DD_HH_MM_SS(15 * 60 * 60 + 51 * 60 + 9)): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: convert_time_...(73 days, 22:04:58) is ok {}." statistical_analysis.increment_number_test_cases_used() if "73 days, 22:04:58" == str( execution_time_measurement. convert_time_in_seconds_to_DD_HH_MM_SS(73 * 24 * 60 * 60 + 22 * 60 * 60 + 4 * 60 + 58)): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
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_get_nearest_integer(): print(" Testing method to round off floating-point numbers.") prompt = " ... Test: 32.5445 -> 33? {}" statistical_analysis.increment_number_test_cases_used() if 33 == number_ops.get_nearest_integer(32.5445): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 8127.9145 -> 8128? {}" statistical_analysis.increment_number_test_cases_used() if 8128 == number_ops.get_nearest_integer(8127.9145): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: 5.19145 -> 5? {}" statistical_analysis.increment_number_test_cases_used() if 5 == number_ops.get_nearest_integer(5.19145): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
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_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!!!"))
def test_get_factorial_recursion(): print(" Testing calculate_factorial.get_factorial_recursion() method.") prompt = " ... Test: get_factorial_recursion(0) {}." statistical_analysis.increment_number_test_cases_used() if 1 == calculate_factorial.get_factorial_recursion(0): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(1) {}." statistical_analysis.increment_number_test_cases_used() if 1 == calculate_factorial.get_factorial_recursion(1): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(2) {}." statistical_analysis.increment_number_test_cases_used() if 2 == calculate_factorial.get_factorial_recursion(2): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(3) {}." statistical_analysis.increment_number_test_cases_used() if 6 == calculate_factorial.get_factorial_recursion(3): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(4) {}." statistical_analysis.increment_number_test_cases_used() if 24 == calculate_factorial.get_factorial_recursion(4): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(5) {}." statistical_analysis.increment_number_test_cases_used() if 120 == calculate_factorial.get_factorial_recursion(5): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(6) {}." statistical_analysis.increment_number_test_cases_used() if 720 == calculate_factorial.get_factorial_recursion(6): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(7) {}." statistical_analysis.increment_number_test_cases_used() if 5040 == calculate_factorial.get_factorial_recursion(7): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(8) {}." statistical_analysis.increment_number_test_cases_used() if 40320 == calculate_factorial.get_factorial_recursion(8): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(9) {}." statistical_analysis.increment_number_test_cases_used() if 362880 == calculate_factorial.get_factorial_recursion(9): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(10) {}." statistical_analysis.increment_number_test_cases_used() if 3628800 == calculate_factorial.get_factorial_recursion(10): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) """ Catch warnings, so that they show up on the command line. \cite{niekas2016} """ with warnings.catch_warnings(record=True) as w: # ValueError: invalid literal for int() with base 10: 'my string' prompt = " ... Test: get_factorial_recursion('my string') {}." statistical_analysis.increment_number_test_cases_used() if None == calculate_factorial.get_factorial_recursion( 'my string'): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion('125.23429') {}." statistical_analysis.increment_number_test_cases_used() if None == calculate_factorial.get_factorial_recursion( '125.23429'): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(None) {}." statistical_analysis.increment_number_test_cases_used() if None == calculate_factorial.get_factorial_recursion(None): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: get_factorial_recursion(-345) {}." statistical_analysis.increment_number_test_cases_used() if None == calculate_factorial.get_factorial_recursion(-345): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!"))
def test_set_reset_and_get_initial_timestamp(): print(" Testing set, reset, get initial timestamp methods.") prompt = " ... Test: get_initial_timestamp() is invalid {}." statistical_analysis.increment_number_test_cases_used() if execution_time_measurement.invalid_timestamp == execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: set_initial_timestamp() not invalid {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp() if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: reset_initial_timestamp() is invalid {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.reset_initial_timestamp() if execution_time_measurement.invalid_timestamp == execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() else: print(prompt.format("FAIL!!!")) prompt = " ... Test: set_initial_timestamp(" ") not invalid {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('perf_counter') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("perf_counter") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('perf_counter_ns') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("perf_counter_ns") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('process_time') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("process_time") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('process_time_ns') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("process_time_ns") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('time') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("time") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('time_ns') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("time_ns") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('monotonic') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("monotonic") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!")) if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): warnings.warn("Initial time stamp not reset between test cases.") prompt = " ... Test: set_initial_timestamp('monotonic_ns') {}." statistical_analysis.increment_number_test_cases_used() execution_time_measurement.set_initial_timestamp("monotonic_ns") if execution_time_measurement.invalid_timestamp != execution_time_measurement.get_initial_timestamp( ): print(prompt.format("OK")) statistical_analysis.increment_number_test_cases_passed() """ Reset initial time stamp to test for other input parameters. """ execution_time_measurement.reset_initial_timestamp() else: print(prompt.format("FAIL!!!"))
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_time_operations(): print("") print("") 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!!!"))
def test_configure_sw_application_parameters(): #def test_configure_sw_application_parameter_result_repository(): print("") print("") 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!!!")) #print("location=",config_manager.get_result_repository(),"=") 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!!!"))