-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.py
executable file
·63 lines (47 loc) · 1.71 KB
/
test.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
#!/usr/bin/env python
"""Tests for all modules of the SET solver."""
import os
import shutil
import unittest
from common import IM_DATA_DIR
import card_finder as cf
import classify_card as cc
import extract_shapes as es
from SetGame import SetGame
TMP_DIR = "tmp"
TEST_DATA_DIR = os.path.join(IM_DATA_DIR, "test")
SAMPLE_CARD = os.path.join(TEST_DATA_DIR, "card06.jpg")
SAMPLE_GAME = os.path.join(TEST_DATA_DIR, "setgame12.jpg")
class TestAll(unittest.TestCase):
def rm_tmp(self):
if os.path.exists(TMP_DIR):
shutil.rmtree(TMP_DIR)
def setUp(self):
self.rm_tmp()
def tearDown(self):
self.rm_tmp()
def test_card_finder_e2e(self):
game_num = 7
card_count = 12
game_file = cf.game_img_filename(game_num)
cards = list(cf.find_cards(game_file))
self.assertEqual(len(cards), card_count)
cf.write_cards(cards, out_dir=TMP_DIR)
self.assertEqual(len(os.listdir(TMP_DIR)), card_count)
def test_classify_card_e2e(self):
# this will break if classify_card() is modified to return something
# other than the nearest labeled card filename, like a dict of the attrs
expected_label = "purple-triple-solid-capsule.jpg"
self.assertEqual(cc.classify_card_from_file(SAMPLE_CARD), expected_label)
def test_find_shapes_e2e(self):
# only checks that we get the right number of shapes back
self.assertEqual(len(es.extract_shapes_from_file(SAMPLE_CARD)), 3)
def test_process_card_e2e(self):
# TODO
pass
def test_SetGame(self):
game = SetGame(SAMPLE_GAME)
game.solve()
self.assertEqual(len(game.sets), 6)
if __name__ == "__main__":
unittest.main()