Esempio n. 1
0
 def test_block_close_present(self):
     """Should raise no exceptions if a closing brace is found."""
     with StringIO(VALID_ROUTE_FILE) as route_file:
         parser = RouteParser(route_file)
         try:
             parser._RouteParser__find_block_close()
         except Exception as err:
             self.fail(err)
Esempio n. 2
0
 def test_header_present(self):
     """Should stop right after the header is found."""
     with StringIO(VALID_ROUTE_FILE) as route_file:
         parser = RouteParser(route_file)
         try:
             parser._RouteParser__find_file_header()
         except Exception as err:
             self.fail(err)
         line = route_file.readline().rstrip()
         # should read the first line after the header
         self.assertEqual(
             line, "  network_route { '172.17.67.0/24':     # comment")
Esempio n. 3
0
 def test_missing_open_brace(self):
     """Should raise then correct exception when missing a close brace."""
     with StringIO(MISSING_OPEN_BRACE_FILE) as route_file:
         parser = RouteParser(route_file)
         # NOTE: there is no context manager for ``assertRaises``` in PY26.
         self.assertRaises(StartTokenNotFoundError,
                           parser._RouteParser__parse_one)
Esempio n. 4
0
 def test_block_close_missing(self):
     """Correct exception should be raised when missing a close brace."""
     with StringIO(MISSING_CLOSE_BRACE_FILE) as route_file:
         parser = RouteParser(route_file)
         # NOTE: there is no context manager for ``assertRaises``` in PY26.
         self.assertRaises(EndTokenNotFoundError,
                           parser._RouteParser__parse_one)
Esempio n. 5
0
 def test_header_absent(self):
     """Should raise the correct exception if header doesn't exist."""
     with StringIO(MISSING_HEADER_FILE) as route_file:
         parser = RouteParser(route_file)
         # NOTE: there is no context manager for ``assertRaises``` in PY26.
         self.assertRaises(StartTokenNotFoundError,
                           parser._RouteParser__find_file_header)
Esempio n. 6
0
 def test_parse_all_routes(self):
     """Should parse all routes correctly."""
     with StringIO(VALID_ROUTE_FILE) as route_file:
         parser = RouteParser(route_file)
         self.assertEqual(list(parser.parse()), VALID_ROUTES)
Esempio n. 7
0
 def test_many_routes_present(self):
     """Should correctly return the first parsed route."""
     with StringIO(VALID_ROUTE_FILE) as route_file:
         parser = RouteParser(route_file)
         self.assertEqual(parser._RouteParser__parse_one(), VALID_ROUTES[0])