-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_classes.py
105 lines (75 loc) · 2.95 KB
/
test_classes.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import unittest
from classes import WordCounter
class Knight:
def rank(self):
return 'Knight'
def wound(self):
return "Ow!"
class BlackKnight(Knight):
def wound(self):
return "It's only a flesh wound"
class TestInheritence(unittest.TestCase):
def setUp(self):
self.arthur = Knight()
self.black_knight = BlackKnight()
def test_method_overriding(self):
self.assertEqual(self.arthur.wound(), 'Ow!')
self.assertEqual(self.black_knight.wound(), "It's only a flesh wound")
def test_method_inheritence(self):
self.assertEqual(self.arthur.rank(), self.black_knight.rank())
self.assertEqual(self.arthur.rank(), 'Knight')
self.assertEqual(self.black_knight.rank(), 'Knight')
class TestClassMethods(unittest.TestCase):
def test_class_methods(self):
class A:
def __init__(self, x):
self.x = x
@classmethod
def class_method(cls):
return 'class_method'
@classmethod
def add(cls, y):
return cls(y).x + 1
@staticmethod
def static_method():
return 'static'
class B(A):
pass
b = B(3)
self.assertEqual(b.x, 3)
self.assertEqual(b.class_method(), 'class_method')
self.assertEqual(b.add(5), 6)
self.assertEqual(b.static_method(), 'static')
class TestWordCounter(unittest.TestCase):
@unittest.skip("implement WordCounter")
def test_word_counter_initialisation(self):
word_counter = WordCounter()
self.assertEquals(word_counter.count(), 0)
@unittest.skip("implement counting words")
def test_word_counter_count(self):
word_counter = WordCounter()
word_counter.add_word("polly")
word_counter.add_word("parrot")
self.assertEquals(word_counter.count(), 2)
self.assertEquals(word_counter.count(word="polly"), 1)
self.assertEquals(word_counter.count(word="parrot"), 1)
@unittest.skip("check that the count tracks dupes correctly")
def test_word_counter_duplication(self):
word_counter = WordCounter()
for i in range(3):
word_counter.add_word("spam")
self.assertEquals(word_counter.count(), 3)
self.assertEquals(word_counter.count(word="spam"), 3)
@unittest.skip("implement words that haven't been seen")
def test_word_counter_unknown_word(self):
word_counter = WordCounter()
word_counter.add_word("hello")
word_counter.add_word("world")
self.assertEquals(word_counter.count("goodbye"), 0)
class TestCapiClient(unittest.TestCase):
# CAPI has two endpoints: /search and /content_id
# Each endpoint takes common parameters: page-size, api-key
# Using test-driven development;
# create a class hierarchy that creates appropriate url strings for each endpoint
# but whose parameter handling is shared
pass