-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ellipse.py
executable file
·47 lines (35 loc) · 1.47 KB
/
test_ellipse.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
#!/usr/bin/env python3
import ellipse
import shutil, tempfile
import filecmp
import unittest
def _slurp_file(filepath):
with open( filepath ) as fd: contents = fd.read()
return contents
class EllipseTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Create a temporary directory before all the tests
cls.test_dir = tempfile.mkdtemp()
ellipse.create_drawings( cls.test_dir )
@classmethod
def tearDownClass(cls):
# Remove the directory after all the tests
shutil.rmtree( cls.test_dir )
def _compare_one_file(self, filename):
example_contents = _slurp_file( 'examples/' + filename )
test_contents = _slurp_file( self.test_dir + '/' + filename )
self.assertTrue( len(example_contents) > 0 )
self.assertEqual( example_contents, test_contents, msg=filename+' is ok' )
def test_three_foci_without_leftovers(self):
self._compare_one_file('three_foci_without_leftovers.svg')
def test_three_foci_with_leftovers(self):
self._compare_one_file('three_foci_with_leftovers.svg')
def test_four_foci_without_leftovers(self):
self._compare_one_file('four_foci_without_leftovers.svg')
def test_four_foci_with_leftovers(self):
self._compare_one_file('four_foci_with_leftovers.svg')
def test_seven_foci_different_slacks(self):
self._compare_one_file('seven_foci_different_slacks.svg')
if __name__ == '__main__':
unittest.main()