def check_if_file_exists(path: str): """ Check if file exists. """ existence = os.path.isfile(path) test_name = f"Test of file {path}" assert existence, test_name success(test_name)
def main(): """ All your tests here. """ create_test() delete_test() sleep(1) success("Note module test")
def check_if_file_exists(path: str): """ Check if created note exists. """ exists = os.path.isfile(path) if exists: success(f"Test of the {path} file existing.") return os.path.isfile(path)
def check_note_size(): """ Check if created note is correct and has right size. """ note = open(NOTE_PATH) note_content = note.read() assert sys.getsizeof(note_content) > 500, "Note has incorrect size!" success("Test of note size")
def main(): """ Tests facade. """ warn_before_testing() remake_test() remove_test() make_test() success("Config tests")
def remove_test(): """ Testing of the remove method. """ print("\nTesting of the remove method...") config.remove() assert not os.path.isfile(CONFIG_PATH), "Config exists after removing!" success("Remove method tests")
def remake_test(): """ Testing of the remake method. """ print("\nTesting of the remake method...") os.system("python3 ../main.py -reinit") assert os.path.isfile(CONFIG_PATH), "Config file does not exists!" assert os.path.isfile(LOGS_PATH), "Log file does not exists!" success("Remake method tests")
def main(): """ All your tests here. """ print("Start testing...\n") tests = get_all_tests() tests_count = len(tests) for test_name, test in tests.items(): run_test(test, test_name) success(f"Any tests ({tests_count} / {tests_count})")
def delete_test(): """ Testing of the delete method. """ note2 = Note("Doopath", "Test message", full_deadline=DEADLINE_2) note2.create() note2.delete() assert not check_if_file_exists( NOTE_PATH_2), "Note existing after deleting!" assert not check_if_file_exists( LOG_PATH_2), "Log file existing after deleting!" success("Test of the note's delete method")
def test2_4(): try: for i in range(1,10): s="file" s+=str(i) os.remove("/mnt/ganesha-mnt/%s"%s) except OSError as ex : print (ex) print "Test 2.4:FAIL" else: success("2.4") global count count = count + 1
def make_test(): """ Testing of the make method. """ print("\nTesting of the make method...") remove_file(CONFIG_PATH) remove_file(LOGS_PATH) os.system("python3 ../main.py --init") assert os.path.isfile(CONFIG_PATH), "Config file does not exists!" assert os.path.isfile(LOGS_PATH), "Log file does not exists! "\ "is incorrect (less than 80 byte)!" success("Make method tests")
def test_parameters(): """ Testing of config_prototype parameters. """ prototype = ConfigPrototype() assert all("" == p["value"] for p in prototype.__dict__.values()), "" \ "Prototype parameter's value can only be equals \"\"!" assert all("" != p["default"] for p in prototype.__dict__.values()), "" \ "Prototype parameter's default value cannot be equals \"\"!" assert all("" != p["main_question"] for p in prototype.__dict__.values()), "" \ "Prototype parameter's main_question cannot be equals \"\"!" assert all("" != p["confirm_question"] for p in prototype.__dict__.values()), "" \ "Prototype parameter's confirm_question cannot be equals \"\"!" success("Parameters test")
def test2_1 (): #message.header2("2.1") try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'w') fo.close() except OSError as ex: print(ex) print " Test 2.1: FAIL" else: success("2.1") global count count = count + 1
def test2_3(): try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'r') fo.read(10) fo.close except IOError as ex: print(ex) print "Test 2.3:FAIL" else: success("2.3") global count count = count + 1
def test2_2(): # message.header2("2.1") try: for i in range(1,10): s="file" s+=str(i) #printf1("os.mkdir('/mnt/ganesha-mnt/",s) fo=open('/mnt/ganesha-mnt/%s'%s,'w') fo.write("This is a test to check if the file is written") fo.close except IOError as ex: print (ex) print "Test 2.2:FAIL" else: success("2.2") global count count = count + 1
def read_test(): """ Test of the read method. """ config_content = config_reader.read() check_config_is_correct(config_content) test_name = "mock_name" test_value = "mock_value" write_mock_parameter(test_name, test_value) config_content = config_reader.read() check_if_correct_parameter(config_content, test_name, test_value) erase_mock_parameter(test_name) config_content = config_reader.read() check_if_parameter_not_exists(config_content, test_name) check_config_is_correct(config_content) success("Test of the read method")
def create_test(): """ Testing of the create method. """ note = Note("Doopath", "Test message", full_deadline=DEADLINE) note.create() sleep(1) assert check_if_file_exists( NOTE_PATH), "Note doesn't exists after creating!" assert check_if_file_exists( LOG_PATH), "Log file doesn't exists after creating!" check_note_size() wait_note_deleting() assert not check_if_file_exists( NOTE_PATH), "Note existing after ended deadline!" assert not check_if_file_exists( LOG_PATH), "Log file existing after ended deadline!" success("Test of the note's create method")
def main(): """ Main function of the action handler tests. """ reduce_test() success("Action handler tests")
def main(): """ Run all tests of yuigahama module. """ make_note_test() success("Test of the yuigahama module")
def make_note_test(): """ Testing of the make_note method. """ handler.make_note("Test", deadline=DEADLINE) check_if_file_exists(NOTE_PATH) success("Test of the yuigahama's make_note method")
def main(): """ All tests of methods here. """ read_test() success("Config reader test")
def check_if_correct_parameter(config_content: dict, name: str, value: str): """ Check if config has name: value attribute and it's correct. """ assert config_content[name] == value, f"Wrong parameter in config after writing! "\ f"{name}: {config_content[name]} instead of {name}: {value}." success("Read method successfully found written parameter.")
def check_config_is_correct(config_content: str): """ Check if config has correct size (more than 50b) and length (more than 4 lines). """ check_config_size(config_content) check_config_length(config_content) success("Config validation test")
def check_config_length(config_content: str): """ Check config length is correct. """ assert len(config_content) >= 4, "Incorrect config length!" success("Config length test")
def check_config_size(config_content: str): """ Check if config size is correct. """ config_size = sys.getsizeof(config_content) assert config_size > 50, "Incorrect config size (less than 50 bytes)" success("Config size test")