Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Jul 15, 2024
1 parent b2fd698 commit b0ff318
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_load_fp_without_module_name():
thrift = None
with open('parser-cases/shared.thrift') as thrift_fp:
thrift = load_fp(thrift_fp)
assert thrift.__name__ == 'shared_thrift'
assert thrift.__name__ == '<unknown_thrift>'
assert thrift.__thrift_file__ is None
assert thrift.__thrift_meta__['structs'] == [thrift.SharedStruct]
assert thrift.__thrift_meta__['services'] == [thrift.SharedService]
Expand Down
8 changes: 4 additions & 4 deletions thriftpy2/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None,
return thrift


def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True):
def parse_fp(source, module_name=None, lexer=None, parser=None, enable_cache=True):
"""Parse a file-like object to thrift module object, e.g.::
>>> from thriftpy2.parser.parser import parse_fp
Expand All @@ -630,11 +630,11 @@ def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True):
threadlocal.incomplete_type = CurrentIncompleteType()
threadlocal.initialized = True

if not module_name.endswith('_thrift'):
if module_name is not None and not module_name.endswith('_thrift'):
raise ThriftParserError('thriftpy2 can only generate module with '
'\'_thrift\' suffix')

if enable_cache and module_name in threadlocal.thrift_cache:
if enable_cache and module_name is not None and module_name in threadlocal.thrift_cache:
return threadlocal.thrift_cache[module_name]

if not hasattr(source, 'read'):
Expand All @@ -648,7 +648,7 @@ def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True):

data = source.read()

thrift = types.ModuleType(module_name)
thrift = types.ModuleType(module_name or '<unknown_thrift>')
setattr(thrift, '__thrift_file__', None)
threadlocal.thrift_stack.append(thrift)
lexer.lineno = 1
Expand Down

0 comments on commit b0ff318

Please sign in to comment.