This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_words.py
80 lines (59 loc) · 2.34 KB
/
test_words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: UTF-8 -*-
import platform
if platform.python_version() < '2.7':
import unittest2 as unittest
else:
import unittest
import shutil
import os.path
from tempfile import mkdtemp
from crosswords import words
from crosswords.words import dicts
class TestWords(unittest.TestCase):
def setUp(self):
self.path = mkdtemp()
self._dictpath = dicts.DICTS_PATH
dicts.DICTS_PATH = self.path + '/xde$a4l9'
dicts.init_storage()
with open(dicts.filepath('foo'), 'w') as f:
f.write("abc\ndef\nghi\nwxxx\nwxxx")
def tearDown(self):
shutil.rmtree(self.path, ignore_errors=True)
dicts.DICTS_PATH = self._dictpath
# compile_pattern
def test_compile_empty_word(self):
r = words.compile_pattern('')
self.assertNotEqual(None, r.match(''))
self.assertEqual(None, r.match('a'))
def test_compile_full_word(self):
w = 'foobar'
r = words.compile_pattern(w)
self.assertNotEqual(None, r.match(w))
self.assertEqual(None, r.match('qux'))
self.assertEqual(None, r.match(''))
def test_compile_partial_word(self):
w = 'foobar'
r = words.compile_pattern('fo??ar')
self.assertNotEqual(None, r.match('foobar'))
self.assertNotEqual(None, r.match('footar'))
self.assertEqual(None, r.match('fooobar'))
self.assertEqual(None, r.match('afoobar'))
self.assertEqual(None, r.match('foobara'))
def test_compile_partial_sanitized_word(self):
w = 'foobar'
r = words.compile_pattern(' Fo??a-R')
self.assertNotEqual(None, r.match('foobar'))
self.assertNotEqual(None, r.match('footar'))
self.assertEqual(None, r.match('fooobar'))
self.assertEqual(None, r.match('afoobar'))
self.assertEqual(None, r.match('foobara'))
# get_matches
def test_get_no_matches(self):
self.assertSequenceEqual([], words.get_matches('foo', 'foo'))
def test_get_limited_matches(self):
self.assertSequenceEqual(['abc'], words.get_matches('???', 'foo', 1))
def test_get_matches(self):
self.assertSequenceEqual(['abc', 'def', 'ghi'],
words.get_matches('???', 'foo'))
def test_get_matches_no_duplicates(self):
self.assertSequenceEqual(['wxxx'], words.get_matches('wxx?', 'foo'))