Skip to content

Commit a89eced

Browse files
committed
Add second example unused-local-variable.py, currently defunct
1 parent dde72da commit a89eced

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ jobs:
1717
test:
1818

1919
runs-on: "ubuntu-latest"
20+
21+
services:
22+
23+
cratedb:
24+
image: crate:5.1.1
25+
ports:
26+
- 4200:4200
27+
2028
steps:
2129

2230
- name: Acquire sources
@@ -30,7 +38,7 @@ jobs:
3038

3139
- name: Install dependencies
3240
run: |
33-
pip install pytest
41+
pip install pytest crate[sqlalchemy]
3442
3543
- name: Run tests
3644
run: |

unused-local-variable.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Evaluate CodeQL scan false positive with `py/unused-local-variable`.
3+
4+
Synopsis::
5+
6+
pip install pytest crate[sqlalchemy]
7+
docker run --rm -it --publish=4200:4200 crate:5.1.1
8+
pytest unused-local-variable.py
9+
"""
10+
from unittest.mock import MagicMock, patch
11+
12+
import pytest
13+
import sqlalchemy as sa
14+
from crate.client.cursor import Cursor
15+
from sqlalchemy.orm import declarative_base
16+
17+
pytest.skip(reason="Implementation incomplete", allow_module_level=True)
18+
19+
20+
fake_cursor = MagicMock(name="fake_cursor")
21+
FakeCursor = MagicMock(name="FakeCursor", spec=Cursor)
22+
FakeCursor.return_value = fake_cursor
23+
24+
25+
class DbWrapper:
26+
def __init__(self):
27+
self.engine = sa.create_engine("crate://")
28+
self.Base = declarative_base(bind=self.engine)
29+
30+
31+
@pytest.fixture
32+
def db():
33+
return DbWrapper()
34+
35+
36+
@patch("crate.client.connection.Cursor", FakeCursor)
37+
def test_table_with_object_array(db):
38+
39+
db.Base.metadata.create_all()
40+
fake_cursor.execute.assert_called_with(
41+
(
42+
"\nCREATE TABLE t (\n\t"
43+
"pk STRING, \n\t"
44+
"tags ARRAY(OBJECT), \n\t"
45+
"PRIMARY KEY (pk)\n)\n\n"
46+
),
47+
(),
48+
)

0 commit comments

Comments
 (0)