Show More
@@ -98,11 +98,12 b' def extract_symbols(code, symbols):' | |||
|
98 | 98 | >>> extract_symbols(code, 'A,b,z') |
|
99 | 99 | (["class A: pass", "def b(): return 42"], ['z']) |
|
100 | 100 | """ |
|
101 | symbols = symbols.split(',') | |
|
101 | 102 | try: |
|
102 | 103 | py_code = ast.parse(code) |
|
103 | 104 | except SyntaxError: |
|
104 | 105 | # ignores non python code |
|
105 | return [] | |
|
106 | return [], symbols | |
|
106 | 107 | |
|
107 | 108 | marks = [(getattr(s, 'name', None), s.lineno) for s in py_code.body] |
|
108 | 109 | code = code.split('\n') |
@@ -126,7 +127,7 b' def extract_symbols(code, symbols):' | |||
|
126 | 127 | # fill a list with chunks of codes for each requested symbol |
|
127 | 128 | blocks = [] |
|
128 | 129 | not_found = [] |
|
129 |
for symbol in symbols |
|
|
130 | for symbol in symbols: | |
|
130 | 131 | if symbol in symbols_lines: |
|
131 | 132 | start, end = symbols_lines[symbol] |
|
132 | 133 | blocks.append('\n'.join(code[start:end]) + '\n') |
@@ -79,7 +79,7 b' def test_extract_symbols_ignores_non_python_code():' | |||
|
79 | 79 | "def hello\n" |
|
80 | 80 | "puts 'Hello world'\n" |
|
81 | 81 | "end") |
|
82 | nt.assert_equal(code.extract_symbols(source, "hello"), []) | |
|
82 | nt.assert_equal(code.extract_symbols(source, "hello"), ([], ['hello'])) | |
|
83 | 83 | |
|
84 | 84 | |
|
85 | 85 | def test_rehashx(): |
General Comments 0
You need to be logged in to leave comments.
Login now