Skip to content

Commit

Permalink
Add simple test (#7)
Browse files Browse the repository at this point in the history
* Add simple test

* fix gh action

* format
  • Loading branch information
jmlrt authored Jul 4, 2024
1 parent 4a55e49 commit 30ac2df
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: tests

on:
pull_request:
push:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: python -m pip install .
shell: bash
- run: check-yamlschema -v tests/test.yaml .pre-commit-config.yaml .pre-commit-hooks.yaml .github/workflows/pre-commit.yml
shell: bash
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# .pre-commit-config.yaml
# yaml-language-server: $schema=https://json.schemastore.org/pre-commit-config.json
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-ast
- id: debug-statements
- repo: https://github.com/asottile/pyupgrade
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://json.schemastore.org/pre-commit-hooks.json
- id: check-yamlschema
name: Check YAML schemas
description: Validates YAML files with multiple documents according to their json schemas
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Add this to your `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/jmlrt/check-yamlschema
rev: v0.0.3
rev: v0.0.4
hooks:
- id: check-yamlschema
```
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = check-yamlschema
version = 0.0.3
version = 0.0.4
description = A CLI and pre-commit hooks for jsonschema validation in YAML files with multiple documents
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
51 changes: 51 additions & 0 deletions tests/food.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"food": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"vegetables": {
"type": "string"
}
},
"required": ["vegetables"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"fruits": {
"type": "object",
"properties": {
"citrics": {
"type": "string"
},
"tropical": {
"type": "string"
},
"nuts": {
"type": "string"
},
"sweets": {
"type": "string"
}
},
"required": ["citrics", "tropical", "nuts", "sweets"],
"additionalProperties": false
}
},
"required": ["fruits"],
"additionalProperties": false
}
]
}
}
},
"required": ["food"],
"additionalProperties": false
}
82 changes: 82 additions & 0 deletions tests/person.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"hobbies": {
"type": "array",
"items": {
"type": "string"
}
},
"programming_languages": {
"type": "object",
"properties": {
"java": {
"type": "string",
"enum": ["Beginner", "Intermediate", "Advanced"]
},
"python": {
"type": "string",
"enum": ["Beginner", "Intermediate", "Advanced"]
},
"javascript": {
"type": "string",
"enum": ["Beginner", "Intermediate", "Advanced"]
}
},
"required": ["java", "python", "javascript"],
"additionalProperties": false
},
"favorite_food": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"vegetables": {
"type": "string"
}
},
"required": ["vegetables"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"fruits": {
"type": "object",
"properties": {
"citrics": {
"type": "string"
},
"tropical": {
"type": "string"
},
"nuts": {
"type": "string"
},
"sweets": {
"type": "string"
}
},
"required": ["citrics", "tropical", "nuts", "sweets"],
"additionalProperties": false
}
},
"required": ["fruits"],
"additionalProperties": false
}
]
}
}
},
"required": ["name", "age", "hobbies", "programming_languages", "favorite_food"],
"additionalProperties": false
}
27 changes: 27 additions & 0 deletions tests/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# yaml-language-server: $schema=./food.json
food: # Some YAML document
- vegetables: tomatoes
- fruits:
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
---
# yaml-language-server: $schema=./person.json
name: Martin Devloper # Some other YAML document
age: 26
hobbies:
- painting
- playing_music
- cooking
programming_languages:
java: Intermediate
python: Advanced
javascript: Beginner
favorite_food:
- vegetables: tomatoes
- fruits:
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins

0 comments on commit 30ac2df

Please sign in to comment.