Exemplo n.º 1
0
 def validation_of_input(self):  # проверка правильности ввода
     """Input 1-50"""
     check = self.ent.get()
     if check.isdigit() and check.count(' ') == 0:
         self.number = int(check)
         if self.number > 50 or self.number < 1:
             self.ent.delete(0, 'end')  # стераем текст
         elif 1 <= self.number <= 50:
             self.destroy()  # удаляем окно
             root = Program(self.number, self.lines)  # запускаем graphic.py
             root.mainloop()
     else:
         self.ent.delete(0, 'end')  # стераем текст
class ProgramTest(unittest.TestCase):
    def setUp(self):
        phonebook = MagicMock()
        phonebook.records = []
        self.program = Program(phonebook)
        self.program._read = MagicMock(return_value="")
        self.program._write = MagicMock()

    def test_menu__should__exists(self):
        assert hasattr(self.program, "menu")

    def test_run__should__exist(self):
        hasattr(self.program, "run")
        self.program.run()

    def test_run__should__show_menu_and_wait_for_input(self):
        expectedText = self.program.menu

        self.program.run()

        self.program._write.assert_called_once_with(expectedText)

        self.program._read.assert_called_once_with()

    def test_get_list__should__exists(self):
        assert hasattr(self.program, "getList")

    def test_get_list__should__return_a_list(self):
        entries = self.program.getList()
        self.assertIsNotNone(entries)
        self.assertIsInstance(entries, list)
        # assert hasattr(phonebook, "__iter__"); # is iterable

    def test_getList__when__an_entry_is_added__should__return_a_list_with(
            self):

        # Arrange
        entry = Helper.getTestEntry()

        phonebook = Phonebook(Helper.filename)
        phonebook.records = MagicMock(return_value=[entry])
        program = Program(Helper.filename)

        # Act
        entries = self.program.getList()

        # Assert
        Helper.assertPhonebookContainsEntry(phonebook, entry)

    def test_showList__should__call_getList(self):
        program = Program(Helper.filename)
        list = []

        with patch.object(self.program, "getList",
                          return_value=list) as mock_getList:
            # Act
            self.program.showList()

        mock_getList.assert_called_once_with()
    def test_showList__should__call_getList(self):
        program = Program(Helper.filename)
        list = []

        with patch.object(self.program, "getList",
                          return_value=list) as mock_getList:
            # Act
            self.program.showList()

        mock_getList.assert_called_once_with()
    def test_getList__when__an_entry_is_added__should__return_a_list_with(
            self):

        # Arrange
        entry = Helper.getTestEntry()

        phonebook = Phonebook(Helper.filename)
        phonebook.records = MagicMock(return_value=[entry])
        program = Program(Helper.filename)

        # Act
        entries = self.program.getList()

        # Assert
        Helper.assertPhonebookContainsEntry(phonebook, entry)
Exemplo n.º 5
0
class ProgramTest (unittest.TestCase):

    def setUp(self):
        phonebook = MagicMock()
        phonebook.records = []
        self.program = Program(phonebook)
        self.program._read = MagicMock(return_value="")
        self.program._write = MagicMock()

    def test_menu__should__exists(self):
        assert hasattr(self.program, "menu")

    def test_run__should__exist(self):
        hasattr(self.program, "run")
        self.program.run()

    def test_run__should__show_menu_and_wait_for_input(self):
        expectedText = self.program.menu

        self.program.run()

        self.program._write.assert_called_once_with(expectedText)

        self.program._read.assert_called_once_with()

    def test_get_list__should__exists(self):
        assert hasattr(self.program, "getList")

    def test_get_list__should__return_a_list(self):
        entries = self.program.getList()
        self.assertIsNotNone(entries)
        self.assertIsInstance(entries, list)
        #assert hasattr(phonebook, "__iter__"); # is iterable

    def test_getList__when__an_entry_is_added__should__return_a_list_with(self):

        # Arrange
        entry = Helper.getTestEntry()

        phonebook = Phonebook(Helper.filename)
        phonebook.records = MagicMock(return_value=[entry])
        program = Program(Helper.filename)

        # Act
        entries = self.program.getList()

        # Assert
        Helper.assertPhonebookContainsEntry(phonebook, entry)
Exemplo n.º 6
0
#model = keras.models.load_model('/home/piki/Desktop/faks/Computer_vision/KinFaceW-I_rezultati/src/modelSaved_eph'+str(EPOCH_NUM)+'.dat')
#model = keras.models.load_model('/home/piki/Desktop/faks/Computer_vision/KinFaceW-I_rezultati/src/modelSaved_eph50.dat')

# -----Test data-----
Settings()
from src.settings import n_test_data
n_test_data = int(n_test_data)
correct_cnt = 0
comp_results = []
new_path = images_path[index2:index2 + n_test_data]
for i in range(n_test_data):
    prediction = model.predict(np.array([
        X_test[i],
    ]))
    print(prediction)
    prediction = np.around(prediction)
    real_result = Y_test[i]
    comp_results.append(prediction[0][1])
    print(new_path[i])

    if prediction[0][0] == real_result[0] and prediction[0][1] == real_result[
            1]:
        correct_cnt += 1

# -------GUI--------
print('Accuracy: ' + str(correct_cnt / n_test_data))
print()
Program(images_path[index2:index2 + n_test_data],
        [x[1] for x in Y_test[:n_test_data]], comp_results,
        correct_cnt / n_test_data)
 def setUp(self):
     phonebook = MagicMock()
     phonebook.records = []
     self.program = Program(phonebook)
     self.program._read = MagicMock(return_value="")
     self.program._write = MagicMock()
Exemplo n.º 8
0
 def setUp(self):
     phonebook = MagicMock()
     phonebook.records = []
     self.program = Program(phonebook)
     self.program._read = MagicMock(return_value="")
     self.program._write = MagicMock()
Exemplo n.º 9
0
import sys

from src.phonebook import Phonebook
from src.program import Program

filename = "phonebook.data"


def main(program, argv=None):
    if argv is None:
        argv = sys.argv
    program.run()
    return 0


if __name__ == '__main__':

    phonebook = Phonebook(filename)
    program = Program(phonebook)
    exit_value = main(program)
    sys.exit(exit_value)