rbackup/tests/test_config.py

56 lines
1.6 KiB
Python
Raw Normal View History

2019-04-14 12:26:12 -07:00
"""
2019-04-14 14:56:09 -07:00
.. moduleauthor:: Eric Torres
2019-04-14 12:26:12 -07:00
Tests for the rbackup.config module.
"""
import unittest
from pathlib import Path
from tempfile import NamedTemporaryFile
2019-04-17 11:54:20 -07:00
from unittest.mock import patch
2019-04-14 12:26:12 -07:00
import rbackup.config.config_files as config
2019-04-14 12:26:12 -07:00
# ========== Constants ==========
TESTING_PACKAGE = "rbackup.config"
TESTING_MODULE = f"{TESTING_PACKAGE}.config_files"
2019-04-14 12:26:12 -07:00
# ========== Tests ==========
class TestMergeFiles(unittest.TestCase):
def setUp(self):
self.patched_path = patch(f"{TESTING_MODULE}.Path", spec_set=Path)
self.patched_tempfile = patch(
f"{TESTING_MODULE}.NamedTemporaryFile", spec_set=NamedTemporaryFile
)
self.mocked_path = self.patched_path.start()
self.mocked_tempfile = self.patched_tempfile.start()
def test_returns_path_object(self):
self.assertIsInstance(config.merge_files([]), Path)
def tearDown(self):
2019-04-17 11:53:05 -07:00
patch.stopall()
2019-04-14 12:26:12 -07:00
class TestParseConfig(unittest.TestCase):
def setUp(self):
2019-04-15 23:27:29 -07:00
self.patched_config_file = patch(
f"{TESTING_MODULE}.MAIN_CONFIG_FILE", spec_set=Path
)
2019-04-14 12:26:12 -07:00
self.patched_path = patch(f"{TESTING_MODULE}.Path", spec_set=Path)
2019-04-15 23:27:29 -07:00
self.patched_serialize = patch(f"{TESTING_MODULE}.json")
2019-04-14 12:26:12 -07:00
self.mocked_config_file = self.patched_config_file.start()
self.mocked_path = self.patched_path.start()
2019-04-15 23:27:29 -07:00
self.mocked_serialize = self.patched_serialize.start()
2019-04-14 12:26:12 -07:00
def test_raises_file_not_found_error(self):
self.mocked_config_file.is_file.return_value = False
with self.assertRaises(FileNotFoundError):
config.parse_configfile()
def tearDown(self):
2019-04-17 11:53:05 -07:00
patch.stopall()