Skip to content

Commit

Permalink
Add tests for validating schema files. (#4)
Browse files Browse the repository at this point in the history
* Add tests for validating schema files.

Run lint programs and try to use the latest PyDAX to load each dataset
once.

* Missing space

* Missing license header in tox.ini

* Update tox.ini

Co-authored-by: Brendan Dwyer <brendan.dwyer@ibm.com>

* Update tox.ini

Co-authored-by: Brendan Dwyer <brendan.dwyer@ibm.com>

* Only run flake8 on the tests dir

* Add some assertions to ensure that dataset names and versions match so that pydax doesn't miss any datasets during this test

* Load the local files instead of trying to load remote ones

Otherwise this script won't be testing the new changes

* Sanity check

Co-authored-by: Brendan Dwyer <brendan.dwyer@ibm.com>
  • Loading branch information
xuhdev and bdwyer2 committed Dec 8, 2020
1 parent efde7d5 commit 1ba5a4f
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
63 changes: 63 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: Lint

on: # yamllint disable-line rule:truthy
push:
branches: 'master'
pull_request:
branches: '*'

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

name: Lint
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install Dependencies
run: pip install -U -r requirements/tox.txt
- name: Test
run: tox -e lint -vv

- name: Notify Slack success
if: ${{ success() && github.event_name == 'push' }}
env:
SLACK_WEBHOOK: ${{ secrets.PYDAX_CICD_SLACK_WEBHOOK }}
SLACK_COLOR: good
SLACK_ICON_EMOJI: ":drake-yes:"
SLACK_TITLE: Message (**Lint**)
uses: rtCamp/action-slack-notify@v2

- name: Notify Slack failure
if: ${{ failure() && github.event_name == 'push' }}
env:
SLACK_WEBHOOK: ${{ secrets.PYDAX_CICD_SLACK_WEBHOOK }}
SLACK_COLOR: danger
SLACK_ICON_EMOJI: ":scott-yikes:"
SLACK_TITLE: Message (**Lint**)
uses: rtCamp/action-slack-notify@v2
63 changes: 63 additions & 0 deletions .github/workflows/pydax.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: PyDAX

on: # yamllint disable-line rule:truthy
push:
branches: 'master'
pull_request:
branches: '*'

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

name: PyDAX
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install Dependencies
run: pip install -U -r requirements/tox.txt
- name: Test
run: tox -e pydax -vv

- name: Notify Slack success
if: ${{ success() && github.event_name == 'push' }}
env:
SLACK_WEBHOOK: ${{ secrets.PYDAX_CICD_SLACK_WEBHOOK }}
SLACK_COLOR: good
SLACK_ICON_EMOJI: ":drake-yes:"
SLACK_TITLE: Message (**PyDAX**)
uses: rtCamp/action-slack-notify@v2

- name: Notify Slack failure
if: ${{ failure() && github.event_name == 'push' }}
env:
SLACK_WEBHOOK: ${{ secrets.PYDAX_CICD_SLACK_WEBHOOK }}
SLACK_COLOR: danger
SLACK_ICON_EMOJI: ":scott-yikes:"
SLACK_TITLE: Message (**PyDAX**)
uses: rtCamp/action-slack-notify@v2
25 changes: 25 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

extends: default

ignore: |
.tox
rules:
document-start:
present: false
line-length: disable
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@

This is the repository that we maintain the default DAX schema files for
[PyDAX](https://github.com/codait/pydax).

To run tests locally, run:

$ pip install -U -r requirements/tox.txt # If you are inside a virtual environment, conda environment
$ pip3 install --user -U tox # If you are outside any virtual environment or conda environment

# lint tests
$ tox -e lint
# pydax tests
$ tox -e pydax
2 changes: 2 additions & 0 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flake8 == 3.8.4
yamllint == 1.25.0
1 change: 1 addition & 0 deletions requirements/pydax.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/codait/pydax
1 change: 1 addition & 0 deletions requirements/tox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tox == 3.20.1
48 changes: 48 additions & 0 deletions tests/test_pydax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/env python

#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This scripts tests all files in CODAIT/dax-schemata. It shouldn't report any error.

import yaml

import pydax


pydax.init(
DEFAULT_DATASET_SCHEMA_URL='datasets.yaml',
DEFAULT_FORMAT_SCHEMA_URL='formats.yaml',
DEFAULT_LICENSE_SCHEMA_URL='licenses.yaml'
)

with open('datasets.yaml') as f:
datasets = yaml.safe_load(f)

# Datasets name are the same from the schema files. This helps ensure that PyDAX doesn't miss any dataset during the
# test.
assert frozenset(datasets['datasets']) == frozenset(pydax.list_all_datasets())
# Sanity check. In case of all tests being skipped because of a minor error such as in formatting.
assert len(pydax.list_all_datasets()) > 0

for name, versions in pydax.list_all_datasets().items():
# Versions must be the same from the schema files. This helps ensure that PyDAX doesn't miss any dataset during the
# test.
assert frozenset(datasets['datasets'][name]) == frozenset(versions)
# Sanity check. In case of all tests being skipped because of a minor error such as in formatting.
assert len(versions) > 0
for version in versions:
pydax.load_dataset(name=name, version=version, subdatasets=None)
38 changes: 38 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2020 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

[tox]
envlist = lint, pydax
skipsdist = true

[testenv]
download = true

[testenv:lint]
deps = -r requirements/lint.txt # We put them in this file so dependabot can discover it
commands =
yamllint -c .yamllint.yaml .
flake8 tests

[testenv:pydax]
# We only let the latest development version of pydax to run these tests for now. After the first
# release, we also need to test with the stable versions.
deps = -r requirements/pydax.txt
commands = {envpython} ./tests/test_pydax.py

[flake8]
max-line-length = 120
exclude = .eggs,.git,__pycache__,.tox

0 comments on commit 1ba5a4f

Please sign in to comment.