Commit 53d18d68 authored by Matt Clarkson's avatar Matt Clarkson

Issue #3: First ConfigurationManager tests for constructor.

parent 03d6a986
......@@ -2,15 +2,17 @@
"""Class to load application configuration information from file."""
import json
import sksurgerycore.utilities.file_utilities as f
class ConfigurationManager:
"""
Class to load application configuration for example
at startup of an application.
:param: config_file
:raises:
:raises: ValueError
"""
def __init__(self, file_name, write_on_shutdown=False):
"""
......@@ -20,8 +22,7 @@ class ConfigurationManager:
:params: write_on_shutdown, if True, will write back to the same
file when the destructor is called.
"""
if file_name is None:
if not file_name:
raise ValueError("Empty file_name")
f.validate_is_file(file_name)
......@@ -31,5 +32,3 @@ class ConfigurationManager:
self.file_name = file_name
self.write_on_shutdown = write_on_shutdown
......@@ -8,9 +8,9 @@ import os
def validate_is_file(file_name):
"""
Check if file_name file exists.
Check if file_name exists.
"""
if os.path.isfile(file_name):
return True
raise ValueError('File:' + file_name + ' does not exist')
raise ValueError('File `' + file_name + '` does not exist')
# -*- coding: utf-8 -*-
import pytest
import sksurgerycore.configuration.configuration_manager as m
import sksurgerycore.configuration.configuration_manager as cm
def test_constructor():
pass
def test_constructor_with_empty_filename():
with pytest.raises(ValueError):
manager = cm.ConfigurationManager("")
def test_constructor_with_valid_file():
manager = cm.ConfigurationManager("tests/data/FordPrefect.json")
......@@ -3,9 +3,8 @@
"""
Tests for file_utilities.py
"""
import pytest
import six
import os
from sksurgerycore.utilities import file_utilities as f
......@@ -17,6 +16,5 @@ def test_invalid_file_name():
def test_valid_file_name():
six.print_("pwd=" + os.getcwd())
result = f.validate_is_file("data/FordPrefect.json")
result = f.validate_is_file("tests/data/FordPrefect.json")
assert result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment