Skip to content

Commit

Permalink
Remove dead code, improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
youngmit committed Apr 20, 2020
1 parent 5097cb1 commit a088ebf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 60 deletions.
11 changes: 0 additions & 11 deletions armi/localization/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,6 @@ class SettingNameCollision(SettingException):
"""Exception raise when a setting has already been given the same case-insensitive name"""


class InvalidSettingDefinition(SettingException):
"""Exception raised when specials cannot be processed in settings file"""

def __init__(self, name, attrs):
SettingException.__init__(
self,
"Setting {} found to not have well formed attributes for definition. "
" Recieved {}.".format(name, attrs),
)


class NonexistentSettingsFileError(SettingException):
"""Settings file does not exist"""

Expand Down
15 changes: 0 additions & 15 deletions armi/settings/caseSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,7 @@ def loadFromString(self, string, handleInvalids=True):

def loadAllDefaults(self):
r"""Initializes all setting objects from the default files
Crawls the res folder for all XML files, tries to load them as settings files
and sets all default settings from there. (if there is a duplicate setting it
will throw an error)
Also grabs explicitly-defined Settings objects for framework settings.
The formatting of the file name is important as it clues it in to what's valid.
"""
for dirname, _dirnames, filenames in os.walk(armi.RES):
for filename in filenames:
if filename.lower().endswith("settings.xml"):
#KILLME
raise RuntimeError("Old settings are deprecated")

for fwSetting in fwSettings.getFrameworkSettings():
self.settings[fwSetting.name] = fwSetting

Expand Down
25 changes: 21 additions & 4 deletions armi/settings/tests/test_settings2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ class DummyPlugin2(plugins.ArmiPlugin):
@staticmethod
@plugins.HOOKIMPL
def defineSettings():
return [setting.Option("PLUGIN", "extendableOption")]
return [
setting.Option("PLUGIN", "extendableOption"),
setting.Default("PLUGIN", "extendableOption"),
]


class TestCaseSettings(unittest.TestCase):
def setUp(self):
self.cs = caseSettings.Settings()

def test_tempSet(self):
startVal = self.cs["nCycles"]
self.cs.temporarilySet("nCycles", 55)
self.assertEqual(self.cs["nCycles"], 55)
self.cs.unsetTemporarySettings()
self.assertEqual(self.cs["nCycles"], startVal)


class TestSettings2(unittest.TestCase):
Expand Down Expand Up @@ -157,7 +172,7 @@ def test_pluginValidatorsAreDiscovered(self):
)
)

def test_options(self):
def test_pluginSettings(self):
pm = armi.getPluginManagerOrFail()
pm.register(DummyPlugin1)
# We have a setting; this should be fine
Expand All @@ -170,9 +185,10 @@ def test_options(self):

pm.register(DummyPlugin2)
cs = caseSettings.Settings()
self.assertEqual(cs["extendableOption"], "DEFAULT")
self.assertEqual(cs["extendableOption"], "PLUGIN")
# Now we should have the option from plugin 2; make sure that works
cs["extendableOption"] = "PLUGIN"
self.assertIn("extendableOption", cs.keys())
pm.unregister(DummyPlugin2)
pm.unregister(DummyPlugin1)

Expand All @@ -181,9 +197,10 @@ def test_options(self):
pm.register(DummyPlugin2)
pm.register(DummyPlugin1)
cs = caseSettings.Settings()
self.assertEqual(cs["extendableOption"], "DEFAULT")
self.assertEqual(cs["extendableOption"], "PLUGIN")
cs["extendableOption"] = "PLUGIN"


def test_default(self):
"""Make sure default updating mechanism works."""
a = setting.Setting("testsetting", 0)
Expand Down
12 changes: 11 additions & 1 deletion armi/settings/tests/test_settingsIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import io
import os
import unittest

Expand All @@ -20,6 +21,7 @@
from armi.utils import directoryChangers
from armi import settings
from armi.settings import setting
from armi.settings import settingsIO
from armi.localization import exceptions


Expand All @@ -38,6 +40,15 @@ def test_loadFromXmlFailsOnBadNames(self):
with self.assertRaises(IOError):
ss.loadFromInputFile("this-settings-file-does-not-exist.xml")

def test_invalidFile(self):
with self.assertRaises(exceptions.InvalidSettingsFileError):
cs = settings.caseSettings.Settings()
reader = settingsIO.SettingsReader(cs)
reader.readFromStream(
io.StringIO(r"<uselessTag>¯\_(ツ)_/¯</uselessTag>"),
fmt=settingsIO.SettingsReader.SettingsInputFormat.XML,
)


class SettingsWriterTests(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -91,4 +102,3 @@ def test_cannotLoadSettingsAfterParsingCommandLineSetting(self):

with self.assertRaises(exceptions.StateError):
self.cs.loadFromInputFile("somefile.xml")

20 changes: 0 additions & 20 deletions armi/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,6 @@ def tryLiteralEval(source):
_type_strs = {v: k for k, v in _str_types.items()}


def parseType(source, allowNone=False):
"""Tries to parse a Python type, expecting input to be the type or a string."""
# evaluation
try:
evaluated_source = copy.deepcopy(_str_types[source])
except KeyError:
evaluated_source = source

# none logic
potential_none_value = tryLiteralEval(evaluated_source)
if allowNone and not potential_none_value:
return potential_none_value

# assert everything went well
if not isinstance(evaluated_source, type):
raise TypeError("Cannot evaluate a python type from source {}".format(source))

return evaluated_source


# python's matching truth evaluations of Nones in different primitive types
# str's and unicodes omitted because parseValue denies their use.
_none_types = {
Expand Down
9 changes: 0 additions & 9 deletions armi/utils/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ def test_tryLiteralEval(self):
self.assertEqual(parsing.tryLiteralEval("apple"), "apple")
self.assertEqual(parsing.tryLiteralEval(tuple), tuple)

def test_parseType(self):
self.assertEqual(parsing.parseType("int"), int)
self.assertEqual(parsing.parseType(int), int)
self.assertEqual(parsing.parseType("int", True), int)
with self.assertRaises(TypeError):
parsing.parseType("banana", True)
with self.assertRaises(TypeError):
parsing.parseType("banana")

def test_parseValue(self):
self.assertEqual(parsing.parseValue("5", int), 5)
self.assertEqual(parsing.parseValue(5, int), 5)
Expand Down

0 comments on commit a088ebf

Please sign in to comment.