Пример #1
0
def main():
    parser = ParseArgs()

    try:
        arguments = parser.get_parsed_arguments_command()
    except WrongArgumentException as e:
        print(e)
        sys.exit(1)

    logger = Logger(arguments)
    print(arguments)
    action = arguments.action
    data = arguments.data

    check_connection(logger)
    trusty_list = TrustyNotTrustyList("TrustyList.txt", logger)
    not_trusty_list = TrustyNotTrustyList("NotTrustyList.txt", logger)

    if "check" in action:
        equation_solver = EquationSolver(data, action, logger, trusty_list,
                                         not_trusty_list)
        equation_solver.solve_equation()
    elif action == "add_to_trusty":
        trusty_list.add(data)
    elif action == "remove_from_trusty":
        trusty_list.remove(data)
    elif action == "add_to_not_trusty":
        not_trusty_list.add(data)
    elif action == "remove_from_not_trusty":
        not_trusty_list.remove(data)

    del logger
Пример #2
0
def test_init_logger_not_empty_msgs():
    parser = ParseArgs()
    args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                 "Mark = ",
                                                 "../Logs/Logger.txt")
    logger = Logger(args)
    assert logger.messages
 def test_initLoggerNotEmptyMsgs(self):
     parser = ParseArgs()
     args = parser.get_parsed_arguments_variables("checkBoth",
                                                  "equation",
                                                  "Mark = ",
                                                  "./Logs/Logger.txt")
     logger = Logger(args)
     self.assertTrue(logger.messages)
    def test_sevenLinesInFileAfterDelInitTheLogger(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth",
                                                     "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)
        path = logger.path_name
        del logger

        with open(path, "r") as f:
            data = f.read()

        self.assertEquals(len(data.split("\n")), 8)
Пример #5
0
    def test_getAllCombinationsEmptyTags(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)
        trusty_list = TrustyNotTrustyList("TrustyList.txt", logger)
        not_trusty_list = TrustyNotTrustyList("NotTrustyList.txt", logger)

        es = EquationSolver("Mark = ", "checkBoth", logger, trusty_list,
                            not_trusty_list)

        tags = es.get_all_combinations([])

        self.assertFalse(tags)
Пример #6
0
def test_seven_lines_in_file_after_del_init_logger():
    parser = ParseArgs()
    args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                 "Mark = ",
                                                 "./Logs/Logger.txt")
    logger = Logger(args)
    path = logger.path_name
    del logger

    with open(path, "r") as f:
        data = f.read()

    os.remove(path)

    assert (len(data.split("\n")) == 8)
Пример #7
0
    def test_addedOneElementToEmptyList(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)

        trusty_list = TrustyNotTrustyList("TrustyListTest.txt", logger)
        trusty_list.add("wikipedia")

        cur = trusty_list.cur_list

        os.remove(trusty_list.path_name)

        self.assertTrue(cur)
        self.assertEqual(cur, ["wikipedia"])
    def test_threeMsgsInLoggerAfterTwoOtherMessageMethods(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth",
                                                     "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)
        logger.other_message("test message")
        logger.other_message("another test message")

        self.assertEquals(len(logger.messages), 3)
Пример #9
0
    def test_getAllCombinationsWithoutPermutation(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)
        trusty_list = TrustyNotTrustyList("TrustyList.txt", logger)
        not_trusty_list = TrustyNotTrustyList("NotTrustyList.txt", logger)

        es = EquationSolver("Mark = ", "checkBoth", logger, trusty_list,
                            not_trusty_list)

        tags = es.get_all_combinations_without_permutation(["Mark", "Twain"])

        self.assertTrue(tags)
        self.assertEqual(tags, [("Mark", ), ("Twain", ), ("Mark", "Twain")])
        self.assertEqual(len(tags), 3)
Пример #10
0
def test_three_msgs_in_logger_after_two_message_methods():
    parser = ParseArgs()
    args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                 "Mark = ",
                                                 "./Logs/Logger.txt")
    logger = Logger(args)
    logger.other_message("test message")
    logger.other_message("another test message")

    os.remove(logger.path_name)

    assert (len(logger.messages) == 3)
Пример #11
0
    def test_initCorrectData(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)
        trusty_list = TrustyNotTrustyList("TrustyList.txt", logger)
        not_trusty_list = TrustyNotTrustyList("NotTrustyList.txt", logger)

        es = EquationSolver("Mark = ", "checkBoth", logger, trusty_list,
                            not_trusty_list)

        self.assertEqual(es.logger, logger)
        self.assertEqual(es.trusty_list, trusty_list.cur_list)
        self.assertEqual(es.not_trusty_list, not_trusty_list.cur_list)
        self.assertEqual(es.action, 'checkBoth')
        self.assertEqual(es.tags, ["Mark"])
        self.assertEqual(es.check_data, [])
Пример #12
0
    def test_newFileEmptyLists(self):
        parser = ParseArgs()
        args = parser.get_parsed_arguments_variables("checkBoth", "equation",
                                                     "Mark = ",
                                                     "./Logs/Logger.txt")
        logger = Logger(args)

        trusty_list = TrustyNotTrustyList("TrustyListTest.txt", logger)
        not_trusty_list = TrustyNotTrustyList("NotTrustyListTest.txt", logger)

        t = trusty_list.cur_list
        nt = not_trusty_list.cur_list

        os.remove(trusty_list.path_name)
        os.remove(not_trusty_list.path_name)

        self.assertFalse(t)
        self.assertFalse(nt)