Skip to content

Commit 7e407d4

Browse files
committed
Python: Change (single) test to match codeql database create
1 parent 8ffcff0 commit 7e407d4

File tree

10 files changed

+13
-14
lines changed

10 files changed

+13
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
| Local module | cmd.py:0:0:0:0 | Module cmd | referenced in external file called | pdb.py |
2-
| Local module | cmd.py:0:0:0:0 | Module cmd | referenced in local file called | test_ok.py |
3-
| Local module | unique_name.py:0:0:0:0 | Module unique_name | referenced in local file called | unique_name_use.py |
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| cmd.py:0:0:0:0 | Module cmd |
2-
| test_fail.py:0:0:0:0 | Module test_fail |
3-
| test_ok.py:0:0:0:0 | Module test_ok |
4-
| unique_name.py:0:0:0:0 | Module unique_name |
5-
| unique_name_use.py:0:0:0:0 | Module unique_name_use |
1+
| code-invalid-package-name/cmd.py:0:0:0:0 | Script cmd.py |
2+
| code-invalid-package-name/test_fail.py:0:0:0:0 | Script test_fail.py |
3+
| code-invalid-package-name/test_ok.py:0:0:0:0 | Script test_ok.py |
4+
| code-invalid-package-name/unique_name.py:0:0:0:0 | Script unique_name.py |
5+
| code-invalid-package-name/unique_name_use.py:0:0:0:0 | Script unique_name_use.py |
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| Module 'cmd' (local, not in stdlib, not missing) referenced in local file | test_ok.py:1 |
2-
| Module 'pdb' (external, in stdlib, not missing) referenced in local file | test_fail.py:3 |
3-
| Module 'unique_name' (local, not in stdlib, not missing) referenced in local file | unique_name_use.py:1 |
1+
| Module 'cmd' (external, in stdlib, not missing) referenced in local file | code-invalid-package-name/test_ok.py:1 |
2+
| Module 'pdb' (external, in stdlib, not missing) referenced in local file | code-invalid-package-name/test_fail.py:3 |
3+
| Module 'unique_name' (external, not in stdlib, missing) referenced in local file | code-invalid-package-name/unique_name_use.py:1 |
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
This test shows how we handle modules the shadow a module in the standard library.
22

3-
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/`.
3+
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`).
44

5-
Because we have a `cmd.py` file, whenever the python interpreter sees `import cmd`, that is the file that will be used! --
5+
The results from `LocalModules.ql`, where everything is a script, matches with the extractor :+1:
6+
7+
Because we have a `cmd.py` file, whenever the python interpreter sees `import cmd`, that is the file that will be used!
68

79
* `python test_ok.py` works as intended, and prints `Foo`
810
* `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'`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
semmle-extractor-options: --max-import-depth=2
1+
semmle-extractor-options: --max-import-depth=2 -R code-invalid-package-name/

0 commit comments

Comments
 (0)