Commit 03d6a986 authored by Matt Clarkson's avatar Matt Clarkson

Issue #3: Add file_utilities.py

parent d8428bf6
......@@ -2,15 +2,34 @@
"""Class to load application configuration information from file."""
import sksurgerycore.utilities.file_utilities as f
class ConfigurationManager:
"""
Class to load application configurationm for example
Class to load application configuration for example
at startup of an application.
:param: config_file
:raises:
"""
def __init__(self):
def __init__(self, file_name, write_on_shutdown=False):
"""
Constructor.
:params: file_name, a json file to read
:params: write_on_shutdown, if True, will write back to the same
file when the destructor is called.
"""
pass
if file_name is None:
raise ValueError("Empty file_name")
f.validate_is_file(file_name)
with open(file_name, "r") as read_file:
self.data = json.load(read_file)
self.file_name = file_name
self.write_on_shutdown = write_on_shutdown
# coding=utf-8
"""
Various file utilities.
"""
import os
def validate_is_file(file_name):
"""
Check if file_name file exists.
"""
if os.path.isfile(file_name):
return True
raise ValueError('File:' + file_name + ' does not exist')
{
"researcher": {
"name": "Ford Prefect",
"species": "Betelgeusian",
"relatives": [
{
"name": "Zaphod Beeblebrox",
"species": "Betelgeusian"
}
]
}
}
# coding=utf-8
"""
Tests for file_utilities.py
"""
import pytest
import six
import os
from sksurgerycore.utilities import file_utilities as f
def test_invalid_file_name():
with pytest.raises(ValueError):
f.validate_is_file("/invalid/file/name")
def test_valid_file_name():
six.print_("pwd=" + os.getcwd())
result = f.validate_is_file("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