Objective: Tag schemas should be checked to ensure that they are valid JSON schemas, and the example for each schema is validated against the schema.
I am able to run nosetests on my Mac successfully but no tests are run when I run via github actions.
I have used different approaches to setting the base directory (BASE_EXAMPLES_DIR) for the python script non of which seem to be working. Although running on the Mac with hard coded path worked fine.
Any help will be appreciated. Please find the details below.
Repo set up:
BaseDir
|- /.github/workflows/schema-tests.yaml
|- /schema (xxx.schema.json)
|- /examples/latest ( yyy.json, yyy.yaml)
|- /schema_testing/test_tag_and_examples.py
##################### /schema_testing/test_tag_and_examples.py
1st Approach
import os
import glob
from jsonschema import validate, ValidationError
import yaml
import json
BASE_EXAMPLES_DIR = './tags/examples/latest/'
def test_json_and_yaml_examples_identical():
print()
yaml_example_files = glob.glob(f'{BASE_EXAMPLES_DIR}*.yaml')
print(f"Found files: {yaml_example_files}")
for yaml_example in yaml_example_files:
example_name_ext = os.path.basename(yaml_example)
example_name = os.path.splitext(example_name_ext)[0]
yaml_file_path = f'{BASE_EXAMPLES_DIR}{example_name}.yaml'
json_file_path = f'{BASE_EXAMPLES_DIR}{example_name}.json'
with open(yaml_file_path) as yaml_file:
with open(json_file_path) as json_file:
yaml_load = yaml.full_load(yaml_file)
json_load = json.load(json_file)
print(f'Checking {example_name}')
assert yaml_load == json_load
########
2nd Approach
Import os
import glob
from jsonschema import validate, ValidationError
import yaml
import json
BASE_EXAMPLES_DIR = f"{os.getenv('tests_folder')}/examples/latest/"
def test_json_and_yaml_examples_identical():
print()
yaml_example_files = glob.glob(f'{BASE_EXAMPLES_DIR}*.yaml')
print(f"Found files: {yaml_example_files}")
for yaml_example in yaml_example_files:
example_name_ext = os.path.basename(yaml_example)
example_name = os.path.splitext(example_name_ext)[0]
yaml_file_path = f'{BASE_EXAMPLES_DIR}{example_name}.yaml'
json_file_path = f'{BASE_EXAMPLES_DIR}{example_name}.json'
with open(yaml_file_path) as yaml_file:
with open(json_file_path) as json_file:
yaml_load = yaml.full_load(yaml_file)
json_load = json.load(json_file)
print(f'Checking {example_name}')
assert yaml_load == json_load
##################### /.github/workflows/schema-tests.yaml
name: Schema Tests
on:
pull_request:
branches:
- "**"
workflow_dispatch:
jobs:
test_schema_examples:
runs-on: ubuntu-latest
env:
tests_folder: ./schema
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install pipenv
run: pip install poetry
- name: Install testing environment
working-directory: schemas
run: |
poetry install
- name: Run tests
working-directory: schemas
run: |
poetry run nosetests
############