Esempio n. 1
0
def test_mouse_vs_mouse():
    # given
    computer_mouse_mock = WordSet([])
    animal_mock = WordSet([])
    computer_mouse_mock.count_occurrences = MagicMock(return_value=10)
    animal_mock.count_occurrences = MagicMock(return_value=5)
    inp = object()
    expected = ['computer-mouse']

    # when
    output = list(mouse_vs_mouse(computer_mouse_mock, animal_mock, [inp]))

    # then
    assert expected == output
    computer_mouse_mock.count_occurrences.assert_called_once_with(inp)
    animal_mock.count_occurrences.assert_called_once_with(inp)
Esempio n. 2
0
    def test_complex(self):
        td = TagDict()
        td.add('tag')

        rl = RecordList()
        dt = datetime(year=2021, month=1, day=15, hour=21, minute=13)
        rl.append(Record(dt, note='test'))

        ws = WordSet()
        with self.assertRaises(Exception):
            ws.check_note('test')
        ws.check_note('test', update=True)

        self.assertEqual('0) tag', str(td))
        self.assertEqual('[15.01.2021 21:13:00] <tag> test', str(rl))
        ws.check_note('test')

        db.save()
        db.clear()
        self.assertEqual('', str(td))
        self.assertEqual('', str(rl))
        with self.assertRaises(Exception):
            ws.check_note('test')

        db.load()
        self.assertEqual('0) tag', str(td))
        self.assertEqual('[15.01.2021 21:13:00] <tag> test', str(rl))
        ws.check_note('test')
Esempio n. 3
0
def test_wordset():
    # given
    inp = [
        'your',
        'computer',
        'input',
        'input',
    ]
    sentence = 'Your bla bla bla rodent input.'
    occurences = 2

    # when
    result = WordSet(inp).count_occurrences(sentence)

    # then
    assert occurences == result
Esempio n. 4
0
        if computer_mouse_wordset.count_occurrences(sentence) >= animal_wordset.count_occurrences(sentence):
            yield 'computer-mouse'
        else:
            yield 'animal'


def file_reader(file_name):
    """Return N rows of the file, where N is in first row of the file (N is not included)
    :param file_name: absolute or relative file name
    :return: content of the file
    """
    with open(file_name, 'rt') as input_file:
        n = int(input_file.readline())  # TODO: handle if not a integer
        for _ in range(n):
            yield input_file.readline()


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Mouse vs Mouse')
    parser.add_argument('input', help='input file')
    parser.add_argument('--animal', help='animal set', default='animal.txt')
    parser.add_argument('--computer-mouse', help='computer mouse set', default='computer-mouse.txt')

    args = parser.parse_args()

    computer_mouse_wordset = WordSet(open(args.computer_mouse, 'rt').readlines())
    animal_wordset = WordSet(open(args.animal, 'rt').readlines())

    for output in mouse_vs_mouse(computer_mouse_wordset, animal_wordset, file_reader(args.input)):
        print(output)
Esempio n. 5
0
 def __init__(self):
     self.tag_dict = TagDict()
     self.word_set = WordSet()
     self.record_list = RecordList()
Esempio n. 6
0
 def setUp(self) -> None:
     db.load()
     self._word_set = WordSet()