-
Notifications
You must be signed in to change notification settings - Fork 16
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
2 changed files
with
240 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,124 @@ | ||
import unittest | ||
import sys | ||
import lib50.errors | ||
import lib50.config | ||
|
||
class TestLoad(unittest.TestCase): | ||
class TestLoader(unittest.TestCase): | ||
def test_no_tool(self): | ||
content = "" | ||
config = lib50.config.load(content, "check50") | ||
config = lib50.config.Loader("check50").load(content) | ||
self.assertEqual(config, None) | ||
|
||
def test_falsy_tool(self): | ||
content = "check50: false" | ||
config = lib50.config.load(content, "check50") | ||
config = lib50.config.Loader("check50").load(content) | ||
self.assertFalse(config) | ||
|
||
def test_truthy_tool(self): | ||
content = "check50: true" | ||
config = lib50.config.load(content, "check50") | ||
config = lib50.config.Loader("check50").load(content) | ||
self.assertTrue(config) | ||
|
||
def test_no_files(self): | ||
content = \ | ||
"check50:\n" \ | ||
" dependencies:\n" \ | ||
" - foo" | ||
config = lib50.config.load(content, "check50") | ||
config = lib50.config.Loader("check50").load(content) | ||
self.assertEqual(config, {"dependencies" : ["foo"]}) | ||
|
||
def test_include_file(self): | ||
def test_global_tag(self): | ||
content = \ | ||
"check50:\n" \ | ||
" foo:\n" \ | ||
" - !include baz\n" \ | ||
" bar:\n" \ | ||
" - !include qux" | ||
config = lib50.config.Loader("check50", "include").load(content) | ||
self.assertTrue(config["foo"][0].include) | ||
self.assertEqual(config["foo"][0].value, "baz") | ||
self.assertTrue(config["bar"][0].include) | ||
self.assertEqual(config["bar"][0].value, "qux") | ||
|
||
def test_local_tag(self): | ||
content = \ | ||
"check50:\n" \ | ||
" files:\n" \ | ||
" - !include foo" | ||
config = lib50.config.load(content, "check50") | ||
self.assertTrue(config["files"][0].type == lib50.config.PatternType.Included) | ||
loader = lib50.config.Loader("check50") | ||
loader.scope("files", "include") | ||
config = loader.load(content) | ||
self.assertTrue(config["files"][0].include) | ||
self.assertEqual(config["files"][0].value, "foo") | ||
|
||
def test_exclude_file(self): | ||
content = \ | ||
"check50:\n" \ | ||
" bar:\n" \ | ||
" - !include foo" | ||
loader = lib50.config.Loader("check50") | ||
loader.scope("files", "include", default=False) | ||
with self.assertRaises(lib50.errors.InvalidConfigError): | ||
config = loader.load(content) | ||
|
||
def test_no_default(self): | ||
content = \ | ||
"check50:\n" \ | ||
" files:\n" \ | ||
" - !exclude foo" | ||
config = lib50.config.load(content, "check50") | ||
self.assertTrue(config["files"][0].type == lib50.config.PatternType.Excluded) | ||
" - !INVALID foo" | ||
loader = lib50.config.Loader("check50") | ||
loader.scope("files", "include", default=False) | ||
with self.assertRaises(lib50.errors.InvalidConfigError): | ||
config = loader.load(content) | ||
|
||
def test_require_file(self): | ||
def test_local_default(self): | ||
content = \ | ||
"check50:\n" \ | ||
" files:\n" \ | ||
" - !require foo" | ||
config = lib50.config.load(content, "check50") | ||
self.assertTrue(config["files"][0].type == lib50.config.PatternType.Required) | ||
" - foo" | ||
loader = lib50.config.Loader("check50") | ||
loader.scope("files", default="bar") | ||
config = loader.load(content) | ||
self.assertTrue(config["files"][0].bar) | ||
self.assertEqual(config["files"][0].value, "foo") | ||
|
||
def test_global_default(self): | ||
content = \ | ||
"check50:\n" \ | ||
" files:\n" \ | ||
" - foo" | ||
config = lib50.config.Loader("check50", default="bar").load(content) | ||
self.assertTrue(config["files"][0].bar) | ||
self.assertEqual(config["files"][0].value, "foo") | ||
|
||
def test_multiple_defaults(self): | ||
content = \ | ||
"check50:\n" \ | ||
" foo:\n" \ | ||
" - baz\n" \ | ||
" bar:\n" \ | ||
" - qux" | ||
loader = lib50.config.Loader("check50", default="include") | ||
loader.scope("bar", default="exclude") | ||
config = loader.load(content) | ||
self.assertTrue(config["foo"][0].include) | ||
self.assertEqual(config["foo"][0].value, "baz") | ||
self.assertTrue(config["bar"][0].exclude) | ||
self.assertEqual(config["bar"][0].value, "qux") | ||
|
||
def test_same_tag_default(self): | ||
content = \ | ||
"check50:\n" \ | ||
" foo:\n" \ | ||
" - !include bar\n" \ | ||
" - baz" | ||
config = lib50.config.Loader("check50", "include", default="include").load(content) | ||
self.assertTrue(config["foo"][0].include) | ||
self.assertEqual(config["foo"][0].value, "bar") | ||
self.assertTrue(config["foo"][1].include) | ||
self.assertEqual(config["foo"][1].value, "baz") | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) | ||
unittest.TextTestRunner(verbosity=2).run(suite) |