I'm new to the unittests
module in Python, so the answer may be obvious. I have a bunch of properties I'd like to check that I've stored in a dictionary:
petersen_prop = {
"n_vertex" : 10,
"n_edge" : 15,
...
}
Each "key" is the name of a function and the value is the target I'd like unittests to verify. What works is the rather verbose code:
import unittest
class PetersenGraph(unittest.TestCase):
def setUp(self):
# Create the graph here (not important to the question)
self.args = args
self.adj = adj
def test_n_vertex(self):
self.assertTrue(n_vertex(self.adj,**self.args) ==
petersen_prop["n_vertex"])
def test_n_edge(self):
self.assertTrue(n_edge(self.adj,**self.args) ==
petersen_prop["n_edge"])
# ..... hundreds of similar looking code blocks
unittest.main(verbosity=2)
It seems like I'm violating DRY, I have to copy and paste the same code block over and over. Is there a way to programmatically add these code blocks so unit tests will work as expected? To be clear, I'd like the input to be the dictionary above, and the output to be a unittest object that works identically.