Skip to content

Commit

Permalink
Merge pull request #93 from JoonaTuovinen/master
Browse files Browse the repository at this point in the history
Addresses #86
  • Loading branch information
JamesPHoughton authored Aug 23, 2016
2 parents 2f2d6e1 + 2421af7 commit 2b05895
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pysd/pysd.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,22 @@ def __init__(self, components):
self.components = components

def __str__(self):

""" Return model source file """

# rename the python file to have the original mdl extension.
# This needs to be changed should the python file name generation
# (from the Vensim model filename) change
# JPH: Maybe we should attach the original and the python filenames
# to the model object as attributes?
fn = str(self.components.__file__).split('.')[0] + '.mdl'
return fn
# JT: Might be helpful to return not only the source file, but
# also how the instance differs from that source file. This
# would give a more accurate view of the current model.
return self.mdl_file

@property
def py_model_file(self):
""" Return model's python file """
return str(self.components.__file__)

@property
def mdl_file(self):
""" Return model's vensim source file """
return self.py_model_file.replace('.py', '.mdl')

def run(self, params=None, return_columns=None, return_timestamps=None,
initial_condition='original'):
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_test_pysd.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,15 @@ def test_restart_cache(self):
self.assertEqual(new, 345)
self.assertNotEqual(old, new)

def test_py_model_file(self):
"""Addresses https://github.com/JamesPHoughton/pysd/issues/86"""
import pysd
model = pysd.read_vensim(test_model)
self.assertEqual(model.py_model_file, test_model.replace('.mdl', '.py'))

def test_mdl_file(self):
"""Relates to https://github.com/JamesPHoughton/pysd/issues/86"""
import pysd
model = pysd.read_vensim(test_model)
self.assertEqual(model.mdl_file, test_model)

0 comments on commit 2b05895

Please sign in to comment.