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

Add tests for new python syntax #219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/python_extractor/src/extract_py_imports.rs
Expand Up @@ -143,4 +143,27 @@ def my_fn():
expected.dedup();
assert_eq!(extract(&parsed), expected)
}

#[test]
fn test_syntax_constructs() {
let python_source = r#"
from typing import Union
from foo import perform_cast
value = 1
args = [int, float]
# this is a legal-in-runtime construction
def perform_cast(value, Union[*args])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is legal?

# walrus operator
x := y := 1
"#;

let parsed = PythonProgram::parse(python_source, "tmp.py").unwrap();
let mut expected = vec![
"typing.Union".to_string(),
"foo.perform_cast".to_string(),
];
expected.sort();
expected.dedup();
assert_eq!(extract(&parsed), expected)
}
}