Skip to content

Commit 733ca04

Browse files
authored
ENH: Update noxfile and env (#2)
1 parent 1eae151 commit 733ca04

File tree

11 files changed

+243
-34
lines changed

11 files changed

+243
-34
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,10 @@ logs/
118118

119119
# reports
120120
reports/
121+
122+
# nox
123+
**.nox/
124+
125+
# playwright stuff
126+
**/playwright-*/
127+
**/test-results/

tests/retrolab/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/retrolab/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Retrolab accessibility tests
2+
3+
## :package: Requirements
4+
5+
To run the tests in this directory you need the following pre-requisites:
6+
7+
- mamba
8+
- python > 3.7
9+
- nox
10+
- pyyaml
11+
12+
you can install both nox and pyyaml from the command line with the following command:
13+
14+
```bash
15+
python3 -m pip install nox pyyaml
16+
```
17+
18+
## :zap: Running the tests
19+
20+
1. Make sure you are in the correct directory:
21+
22+
```bash
23+
cd tests/retrolab
24+
```
25+
26+
2. Run the test with nox from the command line:
27+
28+
```bash
29+
nox -s a11y_tests
30+
```
31+
32+
If you are invoking the nox command for the first time, this may take while to install the dependencies and run the tests.

tests/retrolab/noxfile.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
import nox
2-
import time
3-
4-
@nox.session(
5-
venv_backend="mamba",
6-
reuse_venv=True)
7-
def test(session):
8-
# session.conda_install('nodejs=16', channel="conda-forge")
9-
session.conda_install('yarn', channel="conda-forge")
10-
session.install("-r", "requirements.txt")
11-
session.run('yarn', 'install')
12-
session.run('yarn', 'playwright', 'install', 'chromium')
13-
session.run('yarn', 'run', 'test')
2+
from pathlib import Path
3+
from yaml import safe_load
4+
5+
# global variables
6+
FILE = Path(__file__)
7+
TEST_DIR = FILE.parent
8+
ENV_FILE = TEST_DIR / "environment.yml"
9+
10+
# parse the env file
11+
environment = safe_load(ENV_FILE.read_text())
12+
dependencies = environment.get("dependencies")
13+
# note this assumes that the last line is a pip package
14+
# maybe can be improved in the future, but it works for now
15+
requirements = dependencies.pop(-1).get("pip")
16+
17+
18+
def install_environment(session):
19+
"""Install conda dependencies - instead of creating a conda env through
20+
conda env create -f we install dependency into the session venv.
21+
This is faster than recreating, updating or pruning the environment using
22+
conda env...
23+
24+
Args:
25+
session (nox.session): Nox session calling the function
26+
"""
27+
for conda_pkg in dependencies:
28+
# installing conda dependencies
29+
session.conda_install(conda_pkg, channel="conda-forge")
30+
# installing pip dependencies
31+
for pkg in requirements:
32+
# We split each line in case there's a space for `-r`
33+
session.install(*pkg.split())
34+
35+
36+
@nox.session(venv_backend="mamba", reuse_venv=True)
37+
def a11y_tests(session):
38+
install_environment(session)
39+
session.run("yarn", "install")
40+
session.run("yarn", "playwright", "install", "chromium")
41+
session.run("yarn", "run", "test")

tests/retrolab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
"axe-playwright": "^1.1.9",
1919
"expect-axe-playwright": "^1.2.1"
2020
}
21-
}
21+
}

tests/retrolab/playwright.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ const config: PlaywrightTestConfig = {
8282
// },
8383
],
8484

85+
// TODO: enable port 8888 and 9323
86+
// saves results to playwright-report and test-results
8587
webServer: {
8688
command: "yarn start",
8789
port: 8888,

tests/retrolab/requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

tools/Dockerfile

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#
2+
# Dockerfile for jupyter/accessibility development
3+
#
4+
# Usage:
5+
# -------
6+
#
7+
# From the root of the project:
8+
# docker build --rm -f "./tools/Dockerfile" -t <build-tag> "."
9+
#
10+
# To run the image:
11+
# docker run --rm -it <build-tag>
12+
# This image is based on: Ubuntu 20.04 (focal)
13+
# https://hub.docker.com/_/ubuntu/?tab=tags&name=focal
14+
# OS/ARCH: linux/amd64
15+
16+
FROM gitpod/workspace-base:latest
17+
18+
ARG MAMBAFORGE_VERSION="4.10.0-0"
19+
ARG CONDA_ENV=a11y-tests
20+
ARG DEBIAN_FRONTEND=noninteractive
21+
22+
# ---- Configure environment ----
23+
# base HOME for all things in gitpod
24+
ENV GITPOD_HOME=/home/gitpod \
25+
WORKSPACE=/workspace/a11y
26+
27+
ENV CONDA_DIR="${GITPOD_HOME}/mambaforge3" \
28+
SHELL=/bin/bash
29+
ENV PATH=${CONDA_DIR}/bin:$PATH
30+
31+
# Need to specify where we are installing the browsers
32+
ENV PLAYWRIGHT_BROWSERS_PATH="${GITPOD_HOME}/ms-playwright" \
33+
NODE_DEPS_PATH="${GITPOD_HOME}/node_modules"
34+
35+
# -----------------------------------------------------------------------------
36+
# ---- Creating as root - note: make sure to change to gitpod in the end ----
37+
USER root
38+
39+
# hadolint ignore=DL3008
40+
RUN apt-get update && \
41+
apt-get install -yq --no-install-recommends \
42+
build-essential \
43+
ca-certificates \
44+
curl \
45+
dirmngr \
46+
make && \
47+
# this needs to be done after installing dirmngr
48+
apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 && \
49+
apt-add-repository https://cli.github.com/packages && \
50+
apt-get install -yq --no-install-recommends \
51+
gh && \
52+
locale-gen en_US.UTF-8 && \
53+
# clean apt cache
54+
apt-get clean && \
55+
rm -rf /var/cache/apt/* &&\
56+
rm -rf /var/lib/apt/lists/* &&\
57+
rm -rf /tmp/*
58+
59+
# Allows this Dockerfile to activate conda environments
60+
SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]
61+
62+
# -----------------------------------------------------------------------------
63+
# ---- Installing mamba ----
64+
RUN wget -q -O mambaforge3.sh \
65+
"https://github.com/conda-forge/miniforge/releases/download/$MAMBAFORGE_VERSION/Mambaforge-$MAMBAFORGE_VERSION-Linux-x86_64.sh" && \
66+
bash mambaforge3.sh -p ${CONDA_DIR} -b && \
67+
rm mambaforge3.sh
68+
69+
70+
# -----------------------------------------------------------------------------
71+
# ---- Copy conda and config files ----
72+
# Copy conda environment file into the container - this needs to exists inside
73+
# the container to create a conda environment from it
74+
# basic workspace configurations
75+
COPY ./tools/gitpod/workspace_config /usr/local/bin/workspace_config
76+
RUN chmod a+rx /usr/local/bin/workspace_config && \
77+
workspace_config
78+
79+
COPY ./tools/environment.yml /tmp/environment.yml
80+
81+
# -----------------------------------------------------------------------------
82+
# ---- Create conda environment ----
83+
# Install dependencies
84+
RUN mamba env create -f /tmp/environment.yml && \
85+
conda activate ${CONDA_ENV} && \
86+
conda clean --all -f -y && \
87+
rm -rf /tmp/* && \
88+
echo node --version
89+
90+
# -----------------------------------------------------------------------------
91+
# ---- Copy needed files for npm dependencies ----
92+
COPY ./tests/retrolab/package.json package.json
93+
94+
# Only install chromium for now - can change at build time
95+
ARG BROWSERS="chromium"
96+
97+
RUN mkdir ${PLAYWRIGHT_BROWSERS_PATH}
98+
99+
RUN conda activate ${CONDA_ENV} && \
100+
rm -rf ${NODE_DEPS_PATH} && \
101+
npm install -g node-gyp && \
102+
yarn install && \
103+
yarn playwright install ${BROWSERS} && \
104+
rm package.json && \
105+
rm -rf /var/lib/apt/lists/* && \
106+
chmod -R 777 ${PLAYWRIGHT_BROWSERS_PATH}
107+
108+
# -----------------------------------------------------------------------------
109+
# Always make sure we are not root
110+
USER gitpod

tools/environment.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: a11y-tests
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
# for base a11y testing
6+
- nodejs=16.*
7+
- retrolab
8+
- pip
9+
- yarn
10+
# for the notebook example
11+
- ipython
12+
- ipywidgets
13+
- matplotlib
14+
- numpy
15+
- scipy
16+
- pip:
17+
- doit

tools/gitpod/workspace_config

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Basic configurations for the workspace
3+
4+
set -e
5+
6+
# gitpod/workspace-base needs at least one file here
7+
touch /home/gitpod/.bashrc.d/empty
8+
9+
# Add git aliases
10+
git config --global alias.co checkout
11+
git config --global alias.ci commit
12+
git config --global alias.st status
13+
git config --global alias.br branch
14+
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
15+
git config --global alias.type 'cat-file -t'
16+
git config --global alias.dump 'cat-file -p'
17+
18+
# Vanity custom bash prompt - makes it more legible
19+
echo "PS1='\[\e]0;\u \w\a\]\[\033[01;36m\]\u\[\033[m\] > \[\033[38;5;141m\]\w\[\033[m\] \\$ '" >>~/.bashrc
20+
21+
# Enable prompt color in the skeleton .bashrc
22+
# hadolint ignore=SC2016
23+
sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc
24+
25+
# make conda activate command available from /bin/bash (login and interactive)
26+
if [[ ! -f "/etc/profile.d/conda.sh" ]]; then
27+
ln -s ${CONDA_DIR}/etc/profile.d/conda.sh /etc/profile.d/conda.sh
28+
fi
29+
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh" >>~/.bashrc
30+
echo "conda activate a11y-tests" >>~/.bashrc
31+
32+
# Enable prompt color in the skeleton .bashrc
33+
# hadolint ignore=SC2016
34+
sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc

0 commit comments

Comments
 (0)