Skip to content

Commit

Permalink
Fix config tests: reinstantiate singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
benjimin committed May 8, 2019
1 parent dca8c3b commit 53733c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Utilities/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ def set(self, section, option, value=None):
singleton = _ConfigParser(defaults=DEFAULTS)
def ConfigParser():
return singleton
def reset():
"""Re-instantiate ConfigParser (only for use in tests)"""
global singleton
singleton = _ConfigParser(defaults=DEFAULTS)

def cnfGetIniValue(configFile, section, option, default=None):
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
unittest_dir = pathLocate.getUnitTestDirectory()

import Utilities.columns as columns
from Utilities import config

class TestReadCSV(unittest.TestCase):

def setUp(self):
config.reset()
self.configFile = pjoin(unittest_dir, 'test_data','test_cols.ini')
self.inputFile = pjoin(unittest_dir, 'test_data','test_cols.csv')
self.source = 'TEST'
Expand All @@ -22,6 +24,8 @@ def setUp(self):
dtype=[('A', float),
('B', float),
('C', int)])
def tearDown(self):
config.reset()

def test_badinput(self):
self.assertRaises(IOError, columns.colReadCSV,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#from Utilities
import Utilities.config as config #.config import ConfigParser, cnfGetIniValue, parseBool, parseList, formatList
from Utilities.singleton import forgetAllSingletons
from Utilities.config import reset as forgetAllSingletons
import pathLocate

unittest_dir = pathLocate.getUnitTestDirectory()
Expand Down

0 comments on commit 53733c1

Please sign in to comment.