示例#1
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
示例#2
0
    def test_getParsedArgumentsVariablesWrongAction(self):
        parser = ParseArgs()

        with self.assertRaises(WrongArgumentException):
            parser.get_parsed_arguments_variables("add_to_trusty", "equation",
                                                  "Mark = true",
                                                  "./Logs/Logger.txt")
示例#3
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
示例#4
0
def test_get_parsed_arguments_variables_wrong_action():
    parser = ParseArgs()

    with pytest.raises(WrongArgumentException):
        parser.get_parsed_arguments_variables("add_to_trusty", "equation",
                                              "Mark = true",
                                              "./Logs/Logger.txt")
示例#5
0
def test_get_parsed_arguments_variables_correct():
    parser = ParseArgs()
    assert (str(
        parser.get_parsed_arguments_variables(
            "checkBoth", "equation", "Mark = ",
            "./Logs/Logger.txt")) == "Namespace(action='checkBoth', "
            "data='Mark = ', path_name='./Logs/Logger.txt', "
            "type_data='equation')")
 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)
示例#7
0
def test_get_parsed_arguments_variables_wrong_data():
    parser = ParseArgs()

    with pytest.raises(WrongArgumentException):
        parser. \
            get_parsed_arguments_variables("checkBoth",
                                           "equation",
                                           "Mark",
                                           "./Logs/Logger.txt")
示例#8
0
    def test_getParsedArgumentsVariablesWrongData(self):
        parser = ParseArgs()

        with self.assertRaises(WrongArgumentException):
            parser.\
                get_parsed_arguments_variables("checkBoth",
                                               "equation",
                                               "Mark",
                                               "./Logs/Logger.txt")
    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)
示例#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)
    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)
示例#12
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)
示例#13
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)
示例#14
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"])
示例#15
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)
示例#16
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, [])
示例#17
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)