-
Notifications
You must be signed in to change notification settings - Fork 10
TestDrivenDevelopment (TDD) for `pyamidict`
petermr edited this page Sep 28, 2021
·
3 revisions
- goal: to create community code from scratch for
pyamidict, a tool for creating and validating dictionaries. - software:
pytest
The key design is to think of everything that the system would need to do.
Think of a test (maybe a rule). Then create a test for it (which will fail because the software isn't written). Then write just enough code (even if seemingly silly) to make the test pass. Repeat.
Thats it. WE (@shweata and @anuv) went round the cycle about 20 times.
def test_dictionary_exists(self):
assert self.dict1.exists(), f"file should exist {self.dict1}"
Test fails. Create the an empty file ("py4ami/resources/amidicts/dict1.xml"):
self.dict1 = Path(Path(__file__).parent.parent, "py4ami/resources/amidicts/dict1.xml")
... to see if it contains XML
def test_dict_contains_xml_element(self):
root = etree.parse(str(self.dict1))
assert root is not None
edit the file (dict1.xml):
<dictionary>
</dictionary>
... to validate the name of the root element.
def test_dict_has_root_dictionary(self):
root = etree.parse(str(self.dict1)).getroot()
assert root.tag == "dictionary"
... to see if dictionary has a title
def test_dict_has_XML_title(self):
root = etree.parse(str(self.dict1)).getroot()
assert root.attrib["title"] == "dict1"
edit the XML file
<dictionary title="dict1">
</dictionary>
... to see if filename is correct
def test_dict_title_matches_stem_of_filename(self):
root = etree.parse(str(self.dict1)).getroot()
assert root.attrib["title"] == self.dict1.stem
-
Work in very small steps.
-
Do not give files or methods a body until forced to do so.
We haven't got the pytest setup and teardown included yet