Skip to content

Commit 6dd57cc

Browse files
Merge pull request #1142 from datajoint/dev-tests
Migrate nose tests to pytest
2 parents 214891c + 515343b commit 6dd57cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+14765
-160
lines changed

.devcontainer/Dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Note: You can use any Debian/Ubuntu based image you want.
2-
FROM mcr.microsoft.com/devcontainers/python:3.7-bullseye
3-
1+
ARG PY_VER
2+
ARG DISTRO
3+
FROM mcr.microsoft.com/devcontainers/python:${PY_VER}-${DISTRO}
44
RUN \
55
apt update && \
66
apt-get install bash-completion graphviz default-mysql-client -y && \
77
pip install flake8 black faker ipykernel pytest pytest-cov nose nose-cov datajoint && \
88
pip uninstall datajoint -y
99

10+
USER root
1011
ENV DJ_HOST fakeservices.datajoint.io
1112
ENV DJ_USER root
12-
ENV DJ_PASS simple
13+
ENV DJ_PASS password

.devcontainer/devcontainer.json

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
23
{
3-
"name": "Development",
4-
"dockerComposeFile": "docker-compose.yaml",
4+
"name": "Existing Docker Compose (Extend)",
5+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
6+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
7+
"dockerComposeFile": [
8+
"../LNX-docker-compose.yml",
9+
"docker-compose.yml"
10+
],
11+
// The 'service' property is the name of the service for the container that VS Code should
12+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
513
"service": "app",
14+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
15+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
616
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
7-
// Use this environment variable if you need to bind mount your local source code into a new container.
8-
"remoteEnv": {
9-
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
10-
},
11-
// https://containers.dev/features
12-
"features": {
13-
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
14-
"ghcr.io/devcontainers/features/git:1": {},
15-
"ghcr.io/eitsupi/devcontainer-features/jq-likes:1": {},
16-
"ghcr.io/guiyomh/features/vim:0": {}
17-
},
18-
"onCreateCommand": "pip install -e .",
19-
"postStartCommand": "MYSQL_VER=8.0 MINIO_VER=RELEASE.2022-08-11T04-37-28Z docker compose -f local-docker-compose.yml down && docker volume prune -f && MYSQL_VER=8.0 MINIO_VER=RELEASE.2022-08-11T04-37-28Z docker compose -f local-docker-compose.yml up --build --wait",
17+
// Features to add to the dev container. More info: https://containers.dev/features.
18+
// "features": {},
19+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
2020
"forwardPorts": [
2121
80,
2222
443,
2323
3306,
2424
8080,
2525
9000
2626
],
27+
// Uncomment the next line if you want start specific services in your Docker Compose config.
28+
// "runServices": [],
29+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
30+
"shutdownAction": "stopCompose",
31+
"onCreateCommand": "python3 -m pip install -e .",
32+
"features": {
33+
"ghcr.io/devcontainers/features/git:1": {},
34+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
35+
},
36+
// Configure tool-specific properties.
2737
"customizations": {
2838
"vscode": {
2939
"extensions": [
3040
"ms-python.python"
3141
]
3242
}
43+
},
44+
"remoteEnv": {
45+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
3346
}
47+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
48+
// "remoteUser": "devcontainer"
3449
}

.devcontainer/docker-compose.yaml

-10
This file was deleted.

.devcontainer/docker-compose.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '2.4'
2+
services:
3+
# Update this to the name of the service you want to work with in your docker-compose.yml file
4+
app:
5+
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
6+
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
7+
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
8+
# array). The sample below assumes your primary file is in the root of your project.
9+
container_name: datajoint-python-devcontainer
10+
image: datajoint/datajoint-python-devcontainer:${PY_VER:-3.11}-${DISTRO:-buster}
11+
build:
12+
context: .
13+
dockerfile: .devcontainer/Dockerfile
14+
args:
15+
- PY_VER=${PY_VER:-3.11}
16+
- DISTRO=${DISTRO:-buster}
17+
18+
volumes:
19+
# Update this to wherever you want VS Code to mount the folder of your project
20+
- ..:/workspaces:cached
21+
22+
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
23+
# cap_add:
24+
# - SYS_PTRACE
25+
# security_opt:
26+
# - seccomp:unconfined
27+
28+
user: root
29+
30+
# Overrides default command so things don't shut down after the process ends.
31+
command: /bin/sh -c "while sleep 1000; do :; done"
32+

.github/workflows/development.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
py_ver: ["3.9"]
5959
mysql_ver: ["8.0", "5.7"]
6060
include:
61+
- py_ver: "3.11"
62+
mysql_ver: "8.0"
63+
- py_ver: "3.10"
64+
mysql_ver: "8.0"
6165
- py_ver: "3.8"
6266
mysql_ver: "5.7"
6367
- py_ver: "3.7"
@@ -77,7 +81,7 @@ jobs:
7781
- name: Run primary tests
7882
env:
7983
PY_VER: ${{matrix.py_ver}}
80-
DJ_PASS: simple
84+
DJ_PASS: password
8185
MYSQL_VER: ${{matrix.mysql_ver}}
8286
DISTRO: alpine
8387
MINIO_VER: RELEASE.2021-09-03T03-56-13Z

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ docs/site
3030

3131
!.vscode/settings.json
3232
!.vscode/launch.json
33-
!.devcontainer/devcontainer.json
33+
!.devcontainer/devcontainer.json
34+
!.devcontainer/docker-compose.yml
35+

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
## Release notes
22

33
### Upcoming
4+
- Added - Migrate nosetests to pytest - PR [#1142](https://github.com/datajoint/datajoint-python/pull/1142)
45
- Added - Codespell GitHub Actions workflow
56
- Added - GitHub Actions workflow to manually release docs
67
- Changed - Update `datajoint/nginx` to `v0.2.6`
78
- Changed - Migrate docs from `https://docs.datajoint.org/python` to `https://datajoint.com/docs/core/datajoint-python`
9+
- Fixed - [DevContainer](https://containers.dev/) configuration - PR [#1115](https://github.com/datajoint/datajoint-python/pull/1115)
810
- Fixed - Updated set_password to work on MySQL 8 - PR [#1106](https://github.com/datajoint/datajoint-python/pull/1106)
911
- Added - Missing tests for set_password - PR [#1106](https://github.com/datajoint/datajoint-python/pull/1106)
1012
- Changed - Returning success count after the .populate() call - PR [#1050](https://github.com/datajoint/datajoint-python/pull/1050)

LNX-docker-compose.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ x-net:
77
services:
88
db:
99
<<: *net
10-
image: datajoint/mysql:${MYSQL_VER}
10+
image: datajoint/mysql:${MYSQL_VER:-8.0}
1111
environment:
12-
- MYSQL_ROOT_PASSWORD=${DJ_PASS}
12+
- MYSQL_ROOT_PASSWORD=${DJ_PASS:-password}
13+
command: mysqld --default-authentication-plugin=mysql_native_password
1314
# ports:
1415
# - "3306:3306"
1516
# volumes:
@@ -21,7 +22,7 @@ services:
2122
interval: 15s
2223
minio:
2324
<<: *net
24-
image: minio/minio:${MINIO_VER}
25+
image: minio/minio:${MINIO_VER:-RELEASE.2022-08-11T04-37-28Z}
2526
environment:
2627
- MINIO_ACCESS_KEY=datajoint
2728
- MINIO_SECRET_KEY=datajoint
@@ -44,7 +45,7 @@ services:
4445
interval: 15s
4546
fakeservices.datajoint.io:
4647
<<: *net
47-
image: datajoint/nginx:v0.2.6
48+
image: datajoint/nginx:latest
4849
environment:
4950
- ADD_db_TYPE=DATABASE
5051
- ADD_db_ENDPOINT=db:3306
@@ -58,7 +59,7 @@ services:
5859
# - "3306:3306"
5960
app:
6061
<<: *net
61-
image: datajoint/djtest:py${PY_VER}-${DISTRO}
62+
image: datajoint/djtest:py${PY_VER:-3.8}-${DISTRO:-alpine}
6263
depends_on:
6364
db:
6465
condition: service_healthy
@@ -69,7 +70,7 @@ services:
6970
environment:
7071
- DJ_HOST=fakeservices.datajoint.io
7172
- DJ_USER=root
72-
- DJ_PASS
73+
- DJ_PASS=password
7374
- DJ_TEST_HOST=fakeservices.datajoint.io
7475
- DJ_TEST_USER=datajoint
7576
- DJ_TEST_PASSWORD=datajoint
@@ -86,14 +87,12 @@ services:
8687
- -c
8788
- |
8889
set -e
89-
pip install --user nose nose-cov
9090
pip install -e .
9191
pip list --format=freeze | grep datajoint
9292
pytest -sv --cov-report term-missing --cov=datajoint tests
93-
nosetests -vsw tests_old --with-coverage --cover-package=datajoint
9493
# ports:
9594
# - "8888:8888"
96-
user: ${HOST_UID}:anaconda
95+
user: ${HOST_UID:-1000}:anaconda
9796
volumes:
9897
- .:/src
9998
- /tmp/.X11-unix:/tmp/.X11-unix:rw

docs/src/develop.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,16 @@ The following will verify there are no regression errors by running our test sui
3939

4040
- Entire test suite:
4141
```
42-
nosetests -vw tests_old
42+
pytest -sv --cov-report term-missing --cov=datajoint tests
4343
```
44-
> Note: We are in the process of upgrading to `pytest` tests. To run those, use:
45-
> ```
46-
> pytest -sv --cov-report term-missing --cov=datajoint tests
47-
> ```
4844

4945
- A single functional test:
5046
```
51-
nosetests -vs --tests=tests_old.test_external_class:test_insert_and_fetch
47+
pytest -sv tests/test_connection.py::test_dj_conn
5248
```
53-
> Note: We are in the process of upgrading to `pytest` tests. To run those, use:
54-
> ```
55-
> pytest -sv tests/test_connection.py::test_dj_conn
56-
> ```
5749
- A single class test:
5850
```
59-
nosetests -vs --tests=tests_old.test_fetch:TestFetch.test_getattribute_for_fetch1
51+
pytest -sv tests/test_aggr_regressions.py::TestIssue558
6052
```
6153

6254
### Style Tests
@@ -104,7 +96,7 @@ It is often useful in development to connect to DataJoint's relational database
10496
Connect as follows to the database running within your developer environment:
10597

10698
```
107-
mysql -hfakeservices.datajoint.io -uroot -psimple
99+
mysql -hfakeservices.datajoint.io -uroot -ppassword
108100
```
109101

110102
### Documentation

tests/__init__.py

-69
Original file line numberDiff line numberDiff line change
@@ -1,69 +0,0 @@
1-
import datajoint as dj
2-
from packaging import version
3-
import pytest
4-
import os
5-
6-
PREFIX = "djtest"
7-
8-
CONN_INFO_ROOT = dict(
9-
host=os.getenv("DJ_HOST"),
10-
user=os.getenv("DJ_USER"),
11-
password=os.getenv("DJ_PASS"),
12-
)
13-
14-
15-
@pytest.fixture
16-
def connection_root():
17-
"""Root user database connection."""
18-
dj.config["safemode"] = False
19-
connection = dj.Connection(
20-
host=os.getenv("DJ_HOST"),
21-
user=os.getenv("DJ_USER"),
22-
password=os.getenv("DJ_PASS"),
23-
)
24-
yield connection
25-
dj.config["safemode"] = True
26-
connection.close()
27-
28-
29-
@pytest.fixture
30-
def connection_test(connection_root):
31-
"""Test user database connection."""
32-
database = f"{PREFIX}%%"
33-
credentials = dict(
34-
host=os.getenv("DJ_HOST"), user="datajoint", password="datajoint"
35-
)
36-
permission = "ALL PRIVILEGES"
37-
38-
# Create MySQL users
39-
if version.parse(
40-
connection_root.query("select @@version;").fetchone()[0]
41-
) >= version.parse("8.0.0"):
42-
# create user if necessary on mysql8
43-
connection_root.query(
44-
f"""
45-
CREATE USER IF NOT EXISTS '{credentials["user"]}'@'%%'
46-
IDENTIFIED BY '{credentials["password"]}';
47-
"""
48-
)
49-
connection_root.query(
50-
f"""
51-
GRANT {permission} ON `{database}`.*
52-
TO '{credentials["user"]}'@'%%';
53-
"""
54-
)
55-
else:
56-
# grant permissions. For MySQL 5.7 this also automatically creates user
57-
# if not exists
58-
connection_root.query(
59-
f"""
60-
GRANT {permission} ON `{database}`.*
61-
TO '{credentials["user"]}'@'%%'
62-
IDENTIFIED BY '{credentials["password"]}';
63-
"""
64-
)
65-
66-
connection = dj.Connection(**credentials)
67-
yield connection
68-
connection_root.query(f"""DROP USER `{credentials["user"]}`""")
69-
connection.close()

0 commit comments

Comments
 (0)