-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .yamale import make_schema, make_data, validate | ||
from .validator import YamaleTestCase | ||
|
||
__version__ = '1.1.4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
from yamale import YamaleTestCase | ||
|
||
|
||
class TestYaml(YamaleTestCase): | ||
base_dir = os.path.dirname(os.path.realpath(__file__)) | ||
schema = 'fixtures/custom_types.yaml' | ||
yaml = 'fixtures/custom_types_good.yaml' | ||
|
||
def runTest(self): | ||
self.validate() | ||
|
||
|
||
class TestBadYaml(YamaleTestCase): | ||
base_dir = os.path.dirname(os.path.realpath(__file__)) | ||
schema = 'fixtures/custom_types.yaml' | ||
yaml = 'fixtures/custom_types_bad.yaml' | ||
|
||
def runTest(self): | ||
self.validate(exception=ValueError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import glob | ||
import os | ||
from unittest import TestCase | ||
|
||
import yamale | ||
|
||
|
||
class YamaleTestCase(TestCase): | ||
schema = None | ||
yaml = None | ||
base_dir = None | ||
|
||
def validate(self, exception=None): | ||
schema = self.schema | ||
yaml = self.yaml | ||
base_dir = self.base_dir | ||
|
||
if schema is None: | ||
return | ||
|
||
if type(yaml) != list: | ||
yaml = [yaml] | ||
|
||
if base_dir is not None: | ||
schema = os.path.join(base_dir, schema) | ||
yaml = [os.path.join(base_dir, y) for y in yaml] | ||
|
||
yamale_schema = yamale.make_schema(schema) | ||
datas = self.create_data(yaml) | ||
|
||
if exception is None: | ||
self.assertIsNotNone(yamale.validate(yamale_schema, datas)) | ||
else: | ||
self.assertRaises(exception, yamale.validate, yamale_schema, datas) | ||
|
||
def create_data(self, yamls): | ||
paths = set() | ||
for g in yamls: | ||
paths = paths.union(set(glob.glob(g))) | ||
|
||
data = [] | ||
for d in [yamale.make_data(path) for path in paths]: | ||
for c in d: | ||
data.append(c) | ||
|
||
return data |