示例#1
0
def _ElementToString(root):
    """Returns the node as an XML string.

  Args:
    root: The ElementTree.Element instance.

  Returns:
    The XML string.
  """
    output = StringIO()
    ET.ElementTree(root).write(output, 'utf-8')
    return output.getvalue()
示例#2
0
 def testSingleStop(self):
     feed = transitfeed.Schedule()
     kml_file = self.GetTestDataPath('one_stop.kml')
     kmlparser.KMLParser().parse(kml_file, feed)
     stops = feed.get_stop_list()
     self.assertEqual(1, len(stops))
     stop = stops[0]
     self.assertEqual(u'Stop Name', stop.stop_name)
     self.assertAlmostEqual(-93.239037, stop.stop_lon)
     self.assertAlmostEqual(44.854164, stop.stop_lat)
     write_output = StringIO()
     feed.write_google_transit_feed(write_output)
示例#3
0
 def testSingleStop(self):
     feed = transitfeed.Schedule()
     kmlFile = self.GetTestDataPath("one_stop.kml")
     kmlparser.KmlParser().Parse(kmlFile, feed)
     stops = feed.GetStopList()
     self.assertEqual(1, len(stops))
     stop = stops[0]
     self.assertEqual(u"Stop Name", stop.stop_name)
     self.assertAlmostEqual(-93.239037, stop.stop_lon)
     self.assertAlmostEqual(44.854164, stop.stop_lat)
     write_output = StringIO()
     feed.WriteGoogleTransitFeed(write_output)
示例#4
0
    def ConvertDictToZip(self, dict):
        """Converts a dictionary to an in-memory zipfile.

    Arguments:
        dict: A dictionary mapping file names to file contents

    Returns:
        The new file's in-memory contents as a file-like object."""
        zipfile_mem = StringIO()
        zip = zipfile.ZipFile(zipfile_mem, "a")
        for arcname, contents in dict.items():
            zip.writestr(arcname, contents)
        zip.close()
        return zipfile_mem
示例#5
0
    def convert_dict_to_zip(dictionary):
        """Converts a dictionary to an in-memory zipfile.

        Arguments:
            dictionary: A dictionary mapping file names to file contents

        Returns:
            The new file's in-memory contents as a file-like object."""
        zipfile_mem = StringIO()
        zip_file = zipfile.ZipFile(zipfile_mem, 'a')
        for arc_name, contents in dictionary.items():
            zip_file.writestr(arc_name, contents)
        zip_file.close()
        return zipfile_mem
示例#6
0
 def testSingleShape(self):
     feed = transitfeed.Schedule()
     kml_file = self.GetTestDataPath('one_line.kml')
     kmlparser.KMLParser().parse(kml_file, feed)
     shapes = feed.get_shape_list()
     self.assertEqual(1, len(shapes))
     shape = shapes[0]
     self.assertEqual(3, len(shape.points))
     self.assertAlmostEqual(44.854240, shape.points[0][0])
     self.assertAlmostEqual(-93.238861, shape.points[0][1])
     self.assertAlmostEqual(44.853081, shape.points[1][0])
     self.assertAlmostEqual(-93.238708, shape.points[1][1])
     self.assertAlmostEqual(44.852638, shape.points[2][0])
     self.assertAlmostEqual(-93.237923, shape.points[2][1])
     write_output = StringIO()
     feed.write_google_transit_feed(write_output)
示例#7
0
 def testSingleShape(self):
     feed = transitfeed.Schedule()
     kmlFile = self.GetTestDataPath("one_line.kml")
     kmlparser.KmlParser().Parse(kmlFile, feed)
     shapes = feed.GetShapeList()
     self.assertEqual(1, len(shapes))
     shape = shapes[0]
     self.assertEqual(3, len(shape.points))
     self.assertAlmostEqual(44.854240, shape.points[0][0])
     self.assertAlmostEqual(-93.238861, shape.points[0][1])
     self.assertAlmostEqual(44.853081, shape.points[1][0])
     self.assertAlmostEqual(-93.238708, shape.points[1][1])
     self.assertAlmostEqual(44.852638, shape.points[2][0])
     self.assertAlmostEqual(-93.237923, shape.points[2][1])
     write_output = StringIO()
     feed.WriteGoogleTransitFeed(write_output)
示例#8
0
  def testBadEolContext(self):
    """Make sure the filename is included in the report of a bad eol."""

    filename = "routes.txt"
    old_zip = zipfile.ZipFile(
        self.GetPath('tests', 'data', 'good_feed.zip'), 'r')
    content_dict = self.ConvertZipToDict(old_zip)
    old_routes = content_dict[filename]
    new_routes = old_routes.replace('\n', '\r\n', 1)
    self.assertNotEquals(old_routes, new_routes)
    content_dict[filename] = new_routes
    new_zipfile_mem = self.ConvertDictToZip(content_dict)

    options = MockOptions()
    output_file = StringIO()
    feedvalidator.RunValidationOutputToFile(
        new_zipfile_mem, options, output_file)
    self.assertMatchesRegex(filename, output_file.getvalue())
示例#9
0
 def CreateZip(self):
     """Create an in-memory GTFS zipfile from the contents of the file dict."""
     self.zipfile = StringIO()
     self.zip = zipfile.ZipFile(self.zipfile, "a")
     for (arcname, contents) in self.zip_contents.items():
         self.zip.writestr(arcname, contents)
示例#10
0
 def setUp(self):
     self.saved_stdout = sys.stdout
     self.this_stdout = StringIO()
     sys.stdout = self.this_stdout