Test config reader

This commit is contained in:
Jake Howard 2017-05-27 20:32:50 +01:00
parent 9db3b3133d
commit a46f304c55
3 changed files with 19 additions and 4 deletions

View file

@ -4,9 +4,9 @@ from md_pdf.consts import CONFIG_FILE
from md_pdf.exceptions import ConfigValidationException
def load_config():
def load_config(location=CONFIG_FILE):
try:
with open(os.path.join(CONFIG_FILE)) as f:
with open(os.path.join(location)) as f:
return yaml.safe_load(f)
except FileNotFoundError:
raise ConfigValidationException("Can't find config file at {}".format(CONFIG_FILE))

View file

@ -1,9 +1,9 @@
from unittest import TestCase
import unittest
import os
from md_pdf.consts import TEMPLATES_DIR
class BaseTestCase(TestCase):
class BaseTestCase(unittest.TestCase):
def deleteTemplates(self):
for template in [
'header.html',

15
tests/test_config.py Normal file
View 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'))