示例#1
0
  def test_examples(self):
    """
    Run something similar to the examples in the header pydocs.
    """

    # makes a consensus with a couple routers, both with the same nickname

    entry1 = get_router_status_entry_v3({'s': "Fast"})
    entry2 = get_router_status_entry_v3({'s': "Valid"})
    content = get_network_status_document_v3(routers = (entry1, entry2), content = True)

    # first example: parsing via the NetworkStatusDocumentV3 constructor

    consensus_file = StringIO.StringIO(content)
    consensus = NetworkStatusDocumentV3(consensus_file.read())
    consensus_file.close()

    for router in consensus.routers:
      self.assertEqual('caerSidi', router.nickname)

    # second example: using parse_file

    with support_with(StringIO.StringIO(content)) as consensus_file:
      for router in parse_file(consensus_file):
        self.assertEqual('caerSidi', router.nickname)
示例#2
0
    def test_examples(self):
        """
    Run something similar to the examples in the header pydocs.
    """

        # makes a consensus with a couple routers, both with the same nickname

        entry1 = get_router_status_entry_v3({'s': "Fast"})
        entry2 = get_router_status_entry_v3({'s': "Valid"})
        content = get_network_status_document_v3(routers=(entry1, entry2),
                                                 content=True)

        # first example: parsing via the NetworkStatusDocumentV3 constructor

        consensus_file = StringIO.StringIO(content)
        consensus = NetworkStatusDocumentV3(consensus_file.read())
        consensus_file.close()

        for router in consensus.routers:
            self.assertEqual('caerSidi', router.nickname)

        # second example: using parse_file

        with support_with(StringIO.StringIO(content)) as consensus_file:
            for router in parse_file(consensus_file):
                self.assertEqual('caerSidi', router.nickname)
示例#3
0
  def test_parse_file(self):
    """
    Try parsing a document via the parse_file() function.
    """

    entry1 = get_router_status_entry_v3({'s': "Fast"})
    entry2 = get_router_status_entry_v3({'s': "Valid"})
    content = get_network_status_document_v3(routers = (entry1, entry2), content = True)

    # the document that the entries refer to should actually be the minimal
    # descriptor (ie, without the entries)

    expected_document = get_network_status_document_v3()

    descriptor_file = StringIO.StringIO(content)
    entries = list(parse_file(descriptor_file))

    self.assertEquals(entry1, entries[0])
    self.assertEquals(entry2, entries[1])
    self.assertEquals(expected_document, entries[0].document)
示例#4
0
    def test_parse_file(self):
        """
    Try parsing a document via the parse_file() function.
    """

        entry1 = get_router_status_entry_v3({'s': "Fast"})
        entry2 = get_router_status_entry_v3({'s': "Valid"})
        content = get_network_status_document_v3(routers=(entry1, entry2),
                                                 content=True)

        # the document that the entries refer to should actually be the minimal
        # descriptor (ie, without the entries)

        expected_document = get_network_status_document_v3()

        descriptor_file = StringIO.StringIO(content)
        entries = list(parse_file(descriptor_file))

        self.assertEquals(entry1, entries[0])
        self.assertEquals(entry2, entries[1])
        self.assertEquals(expected_document, entries[0].document)