Esempio n. 1
0
 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!!!"))
Esempio n. 2
0
 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!!!"))