def test_add_with_error(self):
     view_model = NodeViewModel()
     view_model.set_input_value("String")
     view_model.add_node()
     self.assertEqual(view_model.get_error(),
                      "Please enter numeric positive value")
     self.assertEqual(
         view_model.get_log_message(),
         "Error occurred: Please enter numeric positive value")
 def test_add_node_with_fake_logger(self):
     view_model = NodeViewModel(logger=FakeLogger())
     view_model.set_input_value(1)
     view_model.add_node()
     self.assertEqual(view_model.get_output_value(), [1])
     self.assertEqual(
         view_model.logger.get_messages(),
         ['Trying to add node with number 1', 'Node added successfully'])
class GUIView(tk.Frame):
    view_model = NodeViewModel()

    def add_node(self):
        self.view_model.set_input_value(self.text_value.get(1, tk.END))
        self.view_model.add_node()
        self.result_label.configure(text=self.view_model.get_output_value)
        self.error_label.configure(text=self.view_model.get_error)

    def remove_node(self):
        self.view_model.set_input_value(self.text_value.get(1, tk.END))
        self.view_model.remove_node()
        self.result_label.configure(text=self.view_model.get_output_value)
        self.error_label.configure(text=self.view_model.get_error)

    def __init__(self):
        tk.Frame.__init__(self)
        self.master.title("AWL Tree")
        self.master.minsize(width=150, height=150)
        self.grid(sticky=tk.W + tk.E + tk.N + tk.S)

        self.add_button = tk.Button(self, text='Add node', width=25, height=5, bg='black', fg='red',
                                    font='arial 14', command=GUIView.add_node)
        self.add_button.pack()

        self.remove_button = tk.Button(self, text='Remove node', width=25, height=5, bg='black', fg='red',
                                       font='arial 14', command=GUIView.remove_node)
        self.remove_button.pack()

        self.text_value = tk.Text(self, height=1, width=30, font="Arial 14")
        self.text_value.pack()

        self.error_label = tk.Label(self, text="", fg='black', font="Arial 14")
        self.error_label.pack()

        self.result_label = tk.Label(self, text="", fg='black', font="Arial 14")
        self.result_label.pack()
class GUIView(tk.Frame):
    view_model = NodeViewModel()
    N_LOG_MESSAGES_TO_DISPLAY = 5

    def add_node(self):
        self.view_model.set_input_value(self.text_value.get(1, tk.END))
        self.view_model.add_node()
        self.result_label.configure(text=self.view_model.get_output_value)
        self.error_label.configure(text=self.view_model.get_error)
        logger_text = '\n'.join(self.view_model.logger.get_log_messages()
                                [-self.N_LOG_MESSAGES_TO_DISPLAY:])
        self.logger.configure(text='%s\n%s' %
                              (self.view_model.get_log_message(), logger_text))

    def remove_node(self):
        self.view_model.set_input_value(self.text_value.get(1, tk.END))
        self.view_model.remove_node()
        self.result_label.configure(text=self.view_model.get_output_value)
        self.error_label.configure(text=self.view_model.get_error)
        logger_text = '\n'.join(self.view_model.logger.get_log_messages()
                                [-self.N_LOG_MESSAGES_TO_DISPLAY:])
        self.logger.configure(text='%s\n%s' %
                              (self.view_model.get_log_message(), logger_text))

    def __init__(self):
        tk.Frame.__init__(self)
        self.master.title("AWL Tree")
        self.master.minsize(width=150, height=150)
        self.grid(sticky=tk.W + tk.E + tk.N + tk.S)

        self.add_button = tk.Button(self,
                                    text='Add node',
                                    width=25,
                                    height=5,
                                    bg='black',
                                    fg='red',
                                    font='arial 14',
                                    command=GUIView.add_node)
        self.add_button.pack()

        self.remove_button = tk.Button(self,
                                       text='Remove node',
                                       width=25,
                                       height=5,
                                       bg='black',
                                       fg='red',
                                       font='arial 14',
                                       command=GUIView.remove_node)
        self.remove_button.pack()

        self.text_value = tk.Text(self, height=1, width=30, font="Arial 14")
        self.text_value.pack()

        self.error_label = tk.Label(self, text="", fg='black', font="Arial 14")
        self.error_label.pack()

        self.result_label = tk.Label(self,
                                     text="",
                                     fg='black',
                                     font="Arial 14")
        self.result_label.pack()

        self.logger = tk.Label(self, text='Log:', bg='black', font="Arial 10")
        self.logger.pack()
 def test_add_many_nodes(self):
     view_model = NodeViewModel()
     view_model.set_input_value(1)
     view_model.add_node()
     view_model.set_input_value(2)
     view_model.add_node()
     view_model.set_input_value(3)
     view_model.add_node()
     view_model.set_input_value(4)
     view_model.add_node()
     view_model.set_input_value(5)
     view_model.add_node()
     view_model.set_input_value(6)
     view_model.add_node()
     view_model.set_input_value(7)
     view_model.add_node()
     view_model.set_input_value(8)
     view_model.add_node()
     view_model.set_input_value(9)
     view_model.add_node()
     self.assertEqual(view_model.get_output_value(),
                      [1, 3, 2, 5, 7, 9, 8, 6, 4])
 def test_remove_last_node(self):
     view_model = NodeViewModel()
     view_model.set_input_value(1)
     view_model.add_node()
     view_model.set_input_value(2)
     view_model.add_node()
     view_model.set_input_value(3)
     view_model.add_node()
     view_model.remove_node()
     self.assertEqual(view_model.get_output_value(), [1, 2])
 def test_create_view_model(self):
     view_model = NodeViewModel()
     self.assertTrue(isinstance(view_model, NodeViewModel))
 def test_add_one_more_node(self):
     view_model = NodeViewModel()
     view_model.set_input_value(1)
     view_model.add_node()
     view_model.set_input_value(2)
     view_model.add_node()
     self.assertEqual(view_model.get_output_value(), [2, 1])
 def test_input_value_setter(self):
     view_model = NodeViewModel()
     view_model.set_input_value(15)
     self.assertEqual(view_model.get_input_value(), 15)