Module tests.test_integration
Classes
class TestIntegration (methodName='runTest')-
Expand source code
class TestIntegration(unittest.TestCase): """The integration tests for this library.""" def test_node_equality(self): """A test to make sure identical data nodes are being treated as equal.""" self.assertEqual(TestingUtils.get_test_node(), TestingUtils.get_test_node()) def test_io(self): """ This test creates a new DataNode, writes it to a file using DataWriter, reads it using DataReader, and compares it against the original node. """ # Write test data to a file writer: DataWriter = DataWriter("test.txt") writer.open() writer.write(TestingUtils.get_test_node()) writer.close() # Read test data from the file reader: DataReader = DataReader("test.txt", DataNode.create_root_node()) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = reader.root.children[0] # Do clean-up Path.unlink(Path("test.txt")) # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node) def test_builder(self): """ This test takes data from the test node, builds it, and makes sure it's working properly. """ # Build the node node: DataNode = TestingUtils.get_test_node() name: str | None = Builder.build_string(node, 0) mass: int = 0 drag: float = 0 description: str | None = "" try: for child in node.children: match child.name: case "mass": mass = Builder.build_int(child, 0) case "drag": drag = Builder.build_float(child, 0) case "description": description = Builder.build_string(child, 0) case _: pass except BuilderError: self.fail() # Check to make sure there were no issues self.assertTrue( name == "Much Confused Wardragon" and mass == 35 and drag == 0.3 and description == "This Wardragon bears no resemblance to any actual ship in the game Endless Sky. It has no material existence, despite having mass and possibly explaining the existence of the dark matter in our universe." ) def test_human_readable_nodes(self): """ This test checks to make sure that nodes with extra empty lines in the middle of their definitions still parse properly. """ # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/humanreadable.txt", root_node) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node) def test_space_indentation(self): """This test checks to make sure that space-based indentation is parsed properly.""" # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/spaceindented.txt", root_node) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node) def test_terrible_indentation(self): """ This test checks to make sure that even the worst indentation can still be parsed, but that the proper warnings are thrown when you attempt to do so. """ # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/terriblyindented.txt", root_node) try: reader.parse() self.fail() except ReaderError: # There should be an error thrown, but everything should still work pass loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node)The integration tests for this library.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
Ancestors
- unittest.case.TestCase
Methods
def test_builder(self)-
Expand source code
def test_builder(self): """ This test takes data from the test node, builds it, and makes sure it's working properly. """ # Build the node node: DataNode = TestingUtils.get_test_node() name: str | None = Builder.build_string(node, 0) mass: int = 0 drag: float = 0 description: str | None = "" try: for child in node.children: match child.name: case "mass": mass = Builder.build_int(child, 0) case "drag": drag = Builder.build_float(child, 0) case "description": description = Builder.build_string(child, 0) case _: pass except BuilderError: self.fail() # Check to make sure there were no issues self.assertTrue( name == "Much Confused Wardragon" and mass == 35 and drag == 0.3 and description == "This Wardragon bears no resemblance to any actual ship in the game Endless Sky. It has no material existence, despite having mass and possibly explaining the existence of the dark matter in our universe." )This test takes data from the test node, builds it, and makes sure it's working properly.
def test_human_readable_nodes(self)-
Expand source code
def test_human_readable_nodes(self): """ This test checks to make sure that nodes with extra empty lines in the middle of their definitions still parse properly. """ # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/humanreadable.txt", root_node) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node)This test checks to make sure that nodes with extra empty lines in the middle of their definitions still parse properly.
def test_io(self)-
Expand source code
def test_io(self): """ This test creates a new DataNode, writes it to a file using DataWriter, reads it using DataReader, and compares it against the original node. """ # Write test data to a file writer: DataWriter = DataWriter("test.txt") writer.open() writer.write(TestingUtils.get_test_node()) writer.close() # Read test data from the file reader: DataReader = DataReader("test.txt", DataNode.create_root_node()) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = reader.root.children[0] # Do clean-up Path.unlink(Path("test.txt")) # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node)This test creates a new DataNode, writes it to a file using DataWriter, reads it using DataReader, and compares it against the original node.
def test_node_equality(self)-
Expand source code
def test_node_equality(self): """A test to make sure identical data nodes are being treated as equal.""" self.assertEqual(TestingUtils.get_test_node(), TestingUtils.get_test_node())A test to make sure identical data nodes are being treated as equal.
def test_space_indentation(self)-
Expand source code
def test_space_indentation(self): """This test checks to make sure that space-based indentation is parsed properly.""" # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/spaceindented.txt", root_node) try: reader.parse() except ReaderError: self.fail() loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node)This test checks to make sure that space-based indentation is parsed properly.
def test_terrible_indentation(self)-
Expand source code
def test_terrible_indentation(self): """ This test checks to make sure that even the worst indentation can still be parsed, but that the proper warnings are thrown when you attempt to do so. """ # Open and parse the test data root_node: DataNode = DataNode.create_root_node() reader: DataReader = DataReader("../testdata/terriblyindented.txt", root_node) try: reader.parse() self.fail() except ReaderError: # There should be an error thrown, but everything should still work pass loaded_node: DataNode = root_node.children[0] # Check to make sure there were no issues self.assertEqual(TestingUtils.get_test_node(), loaded_node)This test checks to make sure that even the worst indentation can still be parsed, but that the proper warnings are thrown when you attempt to do so.