forked from hacktofuture-sjec/hacktofuture4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_parser.py
More file actions
68 lines (49 loc) · 1.79 KB
/
test_parser.py
File metadata and controls
68 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# B32: converted from a print-based scratchpad to proper assertions
# Run with: python -m pytest test_parser.py -v
from server.rsi.parser import parse_file
PY_CODE = '''\
import os
from datetime import datetime
class MyService:
def __init__(self):
pass
def process_data():
pass
'''
JS_CODE = '''\
import React from 'react';
export class App extends React.Component {}
export const doThing = () => {}
'''
def test_python_role_tag():
res = parse_file(PY_CODE, "src/service.py", "mocksha")
assert res["file"]["role_tag"] == "source"
def test_python_symbols():
res = parse_file(PY_CODE, "src/service.py", "mocksha")
names = [s["symbol_name"] for s in res["symbols"]]
assert "MyService" in names
assert "process_data" in names
assert "__init__" in names
def test_python_imports():
res = parse_file(PY_CODE, "src/service.py", "mocksha")
paths = [i["imported_path"] for i in res["imports"]]
assert "os" in paths
assert "datetime" in paths
def test_python_line_count():
res = parse_file(PY_CODE, "src/service.py", "mocksha")
# line_count must be > 1 (was always 1 before B1 fix)
assert res["file"]["line_count"] > 1
def test_python_symbol_start_line():
res = parse_file(PY_CODE, "src/service.py", "mocksha")
class_sym = next(s for s in res["symbols"] if s["symbol_name"] == "MyService")
# MyService is defined after the two import lines, so start_line > 1
assert class_sym["start_line"] > 1
def test_js_symbols():
res = parse_file(JS_CODE, "app.jsx", "mocksha")
names = [s["symbol_name"] for s in res["symbols"]]
assert "App" in names
assert "doThing" in names
def test_js_imports():
res = parse_file(JS_CODE, "app.jsx", "mocksha")
paths = [i["imported_path"] for i in res["imports"]]
assert "react" in paths