Skip to content

Commit

Permalink
Merge pull request #301 from kosack/master
Browse files Browse the repository at this point in the history
Fix tests for Factory and Tool
  • Loading branch information
kosack authored Jan 12, 2017
2 parents 8e21663 + 31014d6 commit 10242fb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
26 changes: 13 additions & 13 deletions ctapipe/core/tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
from traitlets import Unicode, Int


class TestComponentParent(Component):
name = 'TestComponentParent'
class ExampleComponentParent(Component):
name = 'ExampleComponentParent'
value = Int(123, help="").tag(config=True)


class TestComponent1(TestComponentParent):
name = 'TestComponent1'
class ExampleComponent1(ExampleComponentParent):
name = 'ExampleComponent1'
value = Int(123111, help="").tag(config=True)


class TestComponent2(TestComponentParent):
name = 'TestComponent2'
class ExampleComponent2(ExampleComponentParent):
name = 'ExampleComponent2'
value = Int(123222, help="").tag(config=True)


class TestFactory(Factory):
name = 'TestFactory'
class ExampleFactory(Factory):
name = 'ExampleFactory'
description = "Test Factory class"

subclasses = Factory.child_subclasses(TestComponentParent)
subclasses = Factory.child_subclasses(ExampleComponentParent)
subclass_names = [c.__name__ for c in subclasses]

discriminator = Unicode('TestComponent1',
discriminator = Unicode('ExampleComponent1',
help='Product to obtain: {}'
.format(subclass_names)).tag(config=True)

Expand All @@ -40,10 +40,10 @@ def get_product_name(self):


def test_factory():
factory = TestFactory(config=None, tool=None)
factory.discriminator = 'TestComponent2'
factory = ExampleFactory(config=None, tool=None)
factory.discriminator = 'ExampleComponent2'
factory.value = 111
cls = factory.get_class()
obj = cls(config=factory.config, parent=None)
assert(obj.name == 'TestComponent2')
assert(obj.name == 'ExampleComponent2')
assert(obj.value == 111)
12 changes: 11 additions & 1 deletion ctapipe/core/tests/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ class MyTool(Tool):
# test parameters changes:
tool.userparam = 4.0
with pytest.raises(TraitError):
tool.userparam = "badvalue"
tool.userparam = "badvalue"


def test_tool_version():

class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)

tool = MyTool()
assert tool.version_string != ""
6 changes: 2 additions & 4 deletions ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def initialize(self, argv=None):
if self.config_file != '':
self.log.debug("Loading config from '{}'".format(self.config_file))
self.load_config_file(self.config_file)
self.log.info("version {}".format(self.version_string))
self.log.info("ctapipe version {}".format(self.version_string))
self.setup()
self.is_setup = True

Expand Down Expand Up @@ -187,6 +187,4 @@ def run(self, argv=None):
@property
def version_string(self):
""" a formatted version string with version, release, and git hash"""
return "{} [release={}] [githash={}]".format(version,
version.split('+')[0],
version.split('+')[1][3:])
return "{}".format(version)
8 changes: 4 additions & 4 deletions ctapipe/tools/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def info(version=False, tools=False, dependencies=False):

def _info_version():
"""Print version info."""
from ctapipe import version
import ctapipe
print('\n*** ctapipe version info ***\n')
print('version: {0}'.format(version.version))
print('release: {0}'.format(version.release))
print('githash: {0}'.format(version.githash))
print('version: {0}'.format(ctapipe.__version__))
#print('release: {0}'.format(version.release))
#print('githash: {0}'.format(version.githash))
print('')


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# rename _ to -, and prepend 'ctapipe'
entry_points = {}
entry_points['console_scripts'] = [
# 'ctapipe-info = ctapipe.tools.info:main',
'ctapipe-info = ctapipe.tools.info:main',
'ctapipe-camdemo = ctapipe.tools.camdemo:main',
'ctapipe-dump-triggers = ctapipe.tools.dump_triggers:main',
'ctapipe-flow = ctapipe.flow.flow:main'
Expand Down

0 comments on commit 10242fb

Please sign in to comment.