From a46f304c555fddd59edbb0ffc10b7e3a1442ddba Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 May 2017 20:32:50 +0100 Subject: [PATCH] Test config reader --- md_pdf/config/read.py | 4 ++-- tests/__init__.py | 4 ++-- tests/test_config.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/test_config.py diff --git a/md_pdf/config/read.py b/md_pdf/config/read.py index 89633a3..046064b 100644 --- a/md_pdf/config/read.py +++ b/md_pdf/config/read.py @@ -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)) diff --git a/tests/__init__.py b/tests/__init__.py index d04989a..ecff5d9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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', diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..cc66a4d --- /dev/null +++ b/tests/test_config.py @@ -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')) +