Test config reader
This commit is contained in:
parent
9db3b3133d
commit
a46f304c55
3 changed files with 19 additions and 4 deletions
|
@ -4,9 +4,9 @@ from md_pdf.consts import CONFIG_FILE
|
||||||
from md_pdf.exceptions import ConfigValidationException
|
from md_pdf.exceptions import ConfigValidationException
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config(location=CONFIG_FILE):
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(CONFIG_FILE)) as f:
|
with open(os.path.join(location)) as f:
|
||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise ConfigValidationException("Can't find config file at {}".format(CONFIG_FILE))
|
raise ConfigValidationException("Can't find config file at {}".format(CONFIG_FILE))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from unittest import TestCase
|
import unittest
|
||||||
import os
|
import os
|
||||||
from md_pdf.consts import TEMPLATES_DIR
|
from md_pdf.consts import TEMPLATES_DIR
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(TestCase):
|
class BaseTestCase(unittest.TestCase):
|
||||||
def deleteTemplates(self):
|
def deleteTemplates(self):
|
||||||
for template in [
|
for template in [
|
||||||
'header.html',
|
'header.html',
|
||||||
|
|
15
tests/test_config.py
Normal file
15
tests/test_config.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from tests import BaseTestCase
|
||||||
|
from md_pdf.config import read, validate
|
||||||
|
from md_pdf.exceptions import ConfigValidationException
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class ReadConfigTestCase(BaseTestCase):
|
||||||
|
def test_reads_config(self):
|
||||||
|
config = read.load_config(os.path.abspath('test-files/mdp.yml'))
|
||||||
|
self.assertIsInstance(config, dict)
|
||||||
|
|
||||||
|
def test_throws_at_missing_config(self):
|
||||||
|
with self.assertRaises(ConfigValidationException):
|
||||||
|
read.load_config(os.path.abspath('non-existant'))
|
||||||
|
|
Reference in a new issue