예제 #1
0
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)
예제 #2
0
def main():
    """ All your tests here. """
    create_test()
    delete_test()

    sleep(1)
    success("Note module test")
예제 #3
0
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)
예제 #4
0
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")
예제 #5
0
def main():
    """ Tests facade. """
    warn_before_testing()

    remake_test()
    remove_test()
    make_test()

    success("Config tests")
예제 #6
0
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")
예제 #7
0
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")
예제 #8
0
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})")
예제 #9
0
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")
예제 #10
0
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
예제 #11
0
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")
예제 #12
0
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")
예제 #13
0
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
예제 #14
0
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
예제 #15
0
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
예제 #16
0
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")
예제 #17
0
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")
예제 #18
0
def main():
    """ Main function of the action handler tests. """
    reduce_test()

    success("Action handler tests")
예제 #19
0
def main():
    """ Run all tests of yuigahama module. """
    make_note_test()

    success("Test of the yuigahama module")
예제 #20
0
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")
예제 #21
0
def main():
    """ All tests of methods here. """
    read_test()

    success("Config reader test")
예제 #22
0
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.")
예제 #23
0
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")
예제 #24
0
def check_config_length(config_content: str):
    """ Check config length is correct. """
    assert len(config_content) >= 4, "Incorrect config length!"

    success("Config length test")
예제 #25
0
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")