From 6d94719b803d0780d8ae7d0f9420064c9d1e4642 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Sat, 17 Feb 2024 10:22:01 -0800 Subject: [PATCH] Add tests for new python syntax --- .../src/extract_py_imports.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/python_extractor/src/extract_py_imports.rs b/crates/python_extractor/src/extract_py_imports.rs index 62840e5f..05e8690f 100644 --- a/crates/python_extractor/src/extract_py_imports.rs +++ b/crates/python_extractor/src/extract_py_imports.rs @@ -145,4 +145,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]) +# 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) + } }