forked from chaddcw/Python-CI-Testing
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathunittestExample.py
More file actions
executable file
·71 lines (54 loc) · 1.71 KB
/
unittestExample.py
File metadata and controls
executable file
·71 lines (54 loc) · 1.71 KB
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
#!/usr/bin/python3
################################
# File Name: unittestExample.py
# Author: Chadd Williams
# Date: 10/20/2014
# Class: CS 360
# Assignment: Lecture Examples
# Purpose: Demonstrate unit tests
################################
# adapted from https://docs.python.org/3/library/unittest.html
# python3 -m unittest unittestExample -v
import random
import unittest
class TestListFunctions(unittest.TestCase):
listSize = 10
def setUp(self):
""" the text fixture, necessary setup for the tests to run
"""
self.theList = list(range(self.listSize))
# shuffle the list
random.shuffle(self.theList)
def tearDown(self):
""" nothing to tear down here
If your test created a database or built a network connection
you might delete the database or close the network connection
here. You might also close files you opened, close your
TK windows if this is GUI program, or kill threads if this is
a multithreaded application
"""
pass # nothing to do
def test_sort(self):
""" make sure sort works correctly
"""
self.theList.sort()
self.assertEqual(self.theList, list(range(self.listSize)))
def test_append(self):
""" make sure append works correctly
"""
self.theList.append(self.listSize+1)
self.assertEqual(self.theList[-1], self.listSize+1)
def test_exceptions(self):
"""test some exceptions
"""
# theList does not contain -1. Make sure remove
# raised the correct exception
self.assertRaises(ValueError, self.theList.remove, -1)
# def test_thistestwillfail(self):
# """show you what a failed test looks like
# """
#
# # theList DOES contain 1.
# # remove will not raise the expected exception
#
# self.assertRaises(ValueError, self.theList.remove, 0)