Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descriptor from_str() lacks type detection #80

Open
atagar opened this issue Nov 13, 2020 · 0 comments
Open

Descriptor from_str() lacks type detection #80

atagar opened this issue Nov 13, 2020 · 0 comments

Comments

@atagar
Copy link
Contributor

atagar commented Nov 13, 2020

Our Descriptor class' from_str function converts strings to descriptors. When used from a subclass we should (and are documented as) providing a descriptor of that type. However, this fails with...

from stem.descriptor.networkstatus import NetworkStatusDocumentV3

with open('/home/atagar/Desktop/stem/test/unit/descriptor/data/cached-consensus') as consensus_file:
  consensus = NetworkStatusDocumentV3.from_str(consensus_file.read())
Traceback (most recent call last):
  File "broken_demo.py", line 4, in <module>
    consensus = NetworkStatusDocumentV3.from_str(consensus_file.read())
  File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 870, in from_str
    results = list(parse_file(io.BytesIO(stem.util.str_tools._to_bytes(content)), **kwargs))
  File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 448, in parse_file
    for desc in parse(descriptor_file):  # type: ignore
  File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 446, in parse
    raise TypeError("Unable to determine the descriptor's type. filename: '%s', first line: '%s'" % (filename, stem.util.str_tools._to_unicode(first_line)))
TypeError: Unable to determine the descriptor's type. filename: '<undefined>', first line: 'network-status-version 3'

We only have from_str unit tests for server and extrainfo descriptors, which coincidentally work because our parse method can infer their type from the content. This ticket is for two things...

  1. Every descriptor type should have a from_str unit test.
  2. Using from_str with a subclass should populate the descriptor type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant