Skip to content

Commit

Permalink
add nbtest job to the GitHub Actions CI
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jan 30, 2024
1 parent fb3ea3a commit 0e8a47d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: notebook-tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
tests:
runs-on: ubuntu-latest
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
env:
discovery.type: single-node
xpack.security.enabled: false
xpack.security.http.ssl.enabled: false
xpack.license.self_generated.type: trial
ports:
- 9200:9200
steps:
- uses: actions/checkout@v4
- run: sleep 30
- run: PYTHONPATH=. MOCK_ES=1 make test
Empty file added bin/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions bin/mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This module is provided to nbtest when running under GitHub Actions CI to
# mock the Elasticsearch client to always connect on localhost, regardless of
# arguments provided

import elasticsearch

orig_es_init = elasticsearch.Elasticsearch.__init__


def patched_es_init(self, *args, **kwargs):
if 'cloud_id' in kwargs:
assert kwargs['cloud_id'] == 'foo'
if 'api_key' in kwargs:
assert kwargs['api_key'] == 'bar'
return orig_es_init(self, 'http://localhost:9200')


elasticsearch.Elasticsearch.__init__ = patched_es_init
13 changes: 12 additions & 1 deletion bin/nbtest
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [[ ! -f $SCRIPT_DIR/../.venv/bin/nbtest ]]; then
make nbtest
fi

NBTEST="nbtest"
if [[ "$MOCK_ES" != "" ]]; then
export ELASTIC_CLOUD_ID=foo
export ELASTIC_API_KEY=bar
NBTEST="$NBTEST --mocks bin.mocks"

# ensure elasticsearch is installed so that it can be mocked
$SCRIPT_DIR/../.venv/bin/pip install elasticsearch
fi

source $SCRIPT_DIR/../.venv/bin/activate
$SCRIPT_DIR/../.venv/bin/nbtest $*
$SCRIPT_DIR/../.venv/bin/$NBTEST $*
2 changes: 2 additions & 0 deletions notebooks/integrations/hugging-face/.nbtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
masks:
- 'Score: [0-9]+\.[0-9][0-9]*'

0 comments on commit 0e8a47d

Please sign in to comment.