mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Python: Change (single) test to match codeql database create
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
| Local module | cmd.py:0:0:0:0 | Module cmd | referenced in external file called | pdb.py |
|
||||
| Local module | cmd.py:0:0:0:0 | Module cmd | referenced in local file called | test_ok.py |
|
||||
| Local module | unique_name.py:0:0:0:0 | Module unique_name | referenced in local file called | unique_name_use.py |
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
| cmd.py:0:0:0:0 | Module cmd |
|
||||
| test_fail.py:0:0:0:0 | Module test_fail |
|
||||
| test_ok.py:0:0:0:0 | Module test_ok |
|
||||
| unique_name.py:0:0:0:0 | Module unique_name |
|
||||
| unique_name_use.py:0:0:0:0 | Module unique_name_use |
|
||||
| code-invalid-package-name/cmd.py:0:0:0:0 | Script cmd.py |
|
||||
| code-invalid-package-name/test_fail.py:0:0:0:0 | Script test_fail.py |
|
||||
| code-invalid-package-name/test_ok.py:0:0:0:0 | Script test_ok.py |
|
||||
| code-invalid-package-name/unique_name.py:0:0:0:0 | Script unique_name.py |
|
||||
| code-invalid-package-name/unique_name_use.py:0:0:0:0 | Script unique_name_use.py |
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
| Module 'cmd' (local, not in stdlib, not missing) referenced in local file | test_ok.py:1 |
|
||||
| Module 'pdb' (external, in stdlib, not missing) referenced in local file | test_fail.py:3 |
|
||||
| Module 'unique_name' (local, not in stdlib, not missing) referenced in local file | unique_name_use.py:1 |
|
||||
| Module 'cmd' (external, in stdlib, not missing) referenced in local file | code-invalid-package-name/test_ok.py:1 |
|
||||
| Module 'pdb' (external, in stdlib, not missing) referenced in local file | code-invalid-package-name/test_fail.py:3 |
|
||||
| Module 'unique_name' (external, not in stdlib, missing) referenced in local file | code-invalid-package-name/unique_name_use.py:1 |
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
This test shows how we handle modules the shadow a module in the standard library.
|
||||
|
||||
We manually replicate the behavior of `codeql database create --source-root <src-dir>`, which will use `-R <src-dir>`. By default, the way qltest invokes the extractor will cause different behavior. Therefore, we also need to move our code outside of the top-level folder, and it lives in `code/`.
|
||||
We manually replicate the behavior of `codeql database create --source-root <src-dir>`, which will use `-R <src-dir>`. By default, the way qltest invokes the extractor will cause different behavior. Therefore, we also need to move our code outside of the top-level folder, and it lives in `code-invalid-package-name/` -- notice that if we use `code` as the folder name, the extractor will treat it as if there is a package called `code` (note, `codeql database create` would not the folder `code` as a package when `code` is used as the `--source-root`).
|
||||
|
||||
Because we have a `cmd.py` file, whenever the python interpreter sees `import cmd`, that is the file that will be used! --
|
||||
The results from `LocalModules.ql`, where everything is a script, matches with the extractor :+1:
|
||||
|
||||
Because we have a `cmd.py` file, whenever the python interpreter sees `import cmd`, that is the file that will be used!
|
||||
|
||||
* `python test_ok.py` works as intended, and prints `Foo`
|
||||
* `python test_fail.py` raises an exception, since it imports `pdb.py` from the standard library, which (at least in Python 3.8) tries to import `cmd.py` from the standard library, but instead is served our `cmd.py` module. Therefore it fails with `AttributeError: module 'cmd' has no attribute 'Cmd'`
|
||||
|
||||
@@ -1 +1 @@
|
||||
semmle-extractor-options: --max-import-depth=2
|
||||
semmle-extractor-options: --max-import-depth=2 -R code-invalid-package-name/
|
||||
|
||||
Reference in New Issue
Block a user