Skip to content

Commit 7ac75b8

Browse files
committed
1 parent 56518b4 commit 7ac75b8

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

kwalify/README.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ The files in the subdirectories of this folder are organized by the type of file
44

55
## Validation
66

7-
To validate your OpenControl files, use [the Kwalify command-line tool](http://www.kuwata-lab.com/kwalify/ruby/users-guide.05.html#ref-usage).
7+
To validate your OpenControl files, do the following from your project root directory:
88

9-
1. Install Kwalify (requires Ruby).
9+
1. Install Python (2 or 3).
10+
1. Ignore the `schemas/` directory from version control (e.g. `.gitignore`).
11+
1. Clone (or update) the [schemas](https://github.com/opencontrol/schemas) repository.
1012

1113
```bash
12-
gem install kwalify
14+
git clone https://github.com/opencontrol/schemas.git
15+
# or
16+
cd schemas && git pull origin master && cd ..
1317
```
1418

15-
1. Run the validation.
19+
1. Install the dependencies.
1620

21+
```bash
22+
pip install -r pip install -r schemas/kwalify/requirements.txt
1723
```
18-
$ kwalify -f kwalify/component/v3.0.0.yaml path/to/my/component.yaml
19-
path/to/my/component.yaml#0: valid.
20-
```
2124

22-
Note there is also [a Python port](https://github.com/Grokzen/pykwalify).
25+
1. Run the tests.
26+
27+
```bash
28+
pytest
29+
```
2330

24-
For a more advanced setup, see [18F's cloud.gov compliance repository](https://github.com/18F/cg-compliance) as an example of using pykwalify as part of continuous integration.
31+
For a more advanced setup, see [18F's cloud.gov compliance repository](https://github.com/18F/cg-compliance) as an example of using these tests as part of continuous integration.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from glob import iglob
2+
from pykwalify.core import Core
3+
import yaml
4+
5+
def get_schema(version):
6+
path = 'schemas/kwalify/component/v{}.yaml'.format(version)
7+
contents = open(path)
8+
return yaml.load(contents)
9+
10+
def create_validator(source_data):
11+
version = source_data.get('schema_version', '1.0.0')
12+
schema = get_schema(version)
13+
validator = Core(source_data={}, schema_data=schema)
14+
validator.source = source_data
15+
return validator
16+
17+
def test_data_valid():
18+
""" Check that the content of data fits with masonry schema v2 """
19+
for component_file in iglob('*/component.yaml'):
20+
print(component_file)
21+
source_data = yaml.load(open(component_file))
22+
validator = create_validator(source_data)
23+
try:
24+
validator.validate(raise_exception=True)
25+
except:
26+
assert False, "Error found in: {0}".format(component_file)

kwalify/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pykwalify~=1.5.1
2+
pytest~=3.0.0
3+
PyYAML~=3.11

0 commit comments

Comments
 (0)