コード例 #1
0
    def test_loaded(self, actions):
        catalog = {
            Dog.__name__:
            Class(Dog,
                  methods={n: Method(m)
                           for n, m in inspection.methods(Dog)}),
            'stuff':
            Module('stuff',
                   functions={
                       bar1.__name__: Function(bar1),
                       bar2.__name__: Function(bar2),
                       bar3.__name__: Function(bar3),
                   })
        }
        plugins = [
            Plugin('animals', True, Mock(catalog=catalog)),
            Plugin('fish', False, None),
        ]

        container = Mock()
        container.all.return_value = plugins

        actions.collated.return_value = [
            Action('report', None, hours=24),
            Action('reboot', None, minutes=10)
        ]

        # test
        actual = loaded(container, actions)

        # validation
        expected = HELP % {'plugin': plugins[0].name}
        self.assertEqual(expected, actual)
コード例 #2
0
ファイル: test_action.py プロジェクト: darinlively/gofer
    def test_str(self):
        action = Action(Mock(), hours=24)
        action.name = Mock(return_value='1234')

        # test
        s = str(action)

        # validation
        action.name.assert_called_once_with()
        self.assertEqual(s, action.name.return_value)
コード例 #3
0
ファイル: test_action.py プロジェクト: stbenjam/gofer
    def test_str(self):
        action = Action(Mock(), hours=24)
        action.name = Mock(return_value='1234')

        # test
        s = str(action)

        # validation
        action.name.assert_called_once_with()
        self.assertEqual(s, action.name.return_value)
コード例 #4
0
ファイル: test_action.py プロジェクト: darinlively/gofer
 def test_name(self, is_method):
     # method
     is_method.return_value = True
     target = Mock(im_class='KL', __name__='bar')
     action = Action(target, hours=24)
     self.assertEqual(action.name(), 'KL.bar()')
     # function
     is_method.return_value = False
     target = Mock(__module__='MOD', __name__='bar')
     action = Action(target, hours=24)
     self.assertEqual(action.name(), 'MOD.bar()')
コード例 #5
0
    def test_not_called(self, dt):
        now = 3
        dt.utcnow.return_value = now
        target = Mock()
        action = Action('name', target, seconds=10)
        action.last = 1
        action.interval = 2

        # test
        action()

        # validation
        self.assertFalse(target.called)
コード例 #6
0
ファイル: test_action.py プロジェクト: jortel/gofer
    def test_not_called(self, dt):
        now = 3
        dt.utcnow.return_value = now
        target = Mock()
        action = Action('name', target, seconds=10)
        action.last = 1
        action.interval = 2

        # test
        action()

        # validation
        self.assertFalse(target.called)
コード例 #7
0
 def collated():
     collated = []
     collator = Collator()
     classes, functions = collator.collate(Actions.functions)
     for _class, methods in classes.items():
         inst = _class()
         for method, options in methods:
             method = getattr(inst, method.__name__)
             action = Action(method, **options)
             collated.append(action)
     for module, fn_list in functions.items():
         for function, options in fn_list:
             action = Action(function, **options)
             collated.append(action)
     return collated
コード例 #8
0
    def test_call_raised(self, dt):
        now = 4
        dt.utcnow.return_value = now
        target = Mock(side_effect=ValueError)
        action = Action('test', target, seconds=10)
        action.last = 1
        action.interval = 2
        action.name = Mock(return_value='')

        # test
        action()

        # validation
        target.assert_called_once_with()
        self.assertEqual(action.last, now)
コード例 #9
0
ファイル: test_action.py プロジェクト: jortel/gofer
    def test_call_raised(self, dt):
        now = 4
        dt.utcnow.return_value = now
        target = Mock(side_effect=ValueError)
        action = Action('test', target, seconds=10)
        action.last = 1
        action.interval = 2
        action.name = Mock(return_value='')

        # test
        action()

        # validation
        target.assert_called_once_with()
        self.assertEqual(action.last, now)
コード例 #10
0
ファイル: test_action.py プロジェクト: darinlively/gofer
    def test_call(self, dt):
        now = 4
        dt.utcnow.return_value = now
        target = Mock()
        action = Action(target, seconds=10)
        action.last = 1
        action.interval = 2
        action.name = Mock(return_value='')

        # test
        action()

        # validation
        target.assert_called_once_with()
        self.assertEqual(action.last, now)
コード例 #11
0
ファイル: test_action.py プロジェクト: stbenjam/gofer
    def test_call(self, dt):
        now = 4
        dt.utcnow.return_value = now
        target = Mock()
        action = Action(target, seconds=10)
        action.last = 1
        action.interval = 2
        action.name = Mock(return_value='')

        # test
        action()

        # validation
        target.assert_called_once_with()
        self.assertEqual(action.last, now)
コード例 #12
0
    def test_str(self):
        name = 'test'
        action = Action(name, Mock(), hours=24)

        # test
        s = str(action)

        # validation
        self.assertEqual(name, s)
コード例 #13
0
ファイル: test_action.py プロジェクト: stbenjam/gofer
    def test_init(self, delta, dt):
        target = Mock()
        interval = dict(hours=10)

        # test
        action = Action(target, **interval)

        # validation
        delta.assert_called_once_with(**interval)
        dt.assert_called_once_with(1900, 1, 1)
        self.assertEqual(action.target, target)
        self.assertEqual(action.interval, delta.return_value)
        self.assertEqual(action.last, dt.return_value)
コード例 #14
0
ファイル: decorator.py プロジェクト: swipswaps/gofer
 def collated():
     """
     Get a collated list of (decorated) actions.
     :return: List of Action.
     :rtype: list
     """
     collated = []
     collator = Collator()
     classes, functions = collator(Actions.functions)
     namespaces = classes + functions
     for ns in namespaces:
         ns = ns()
         for target in ns:
             action = Action(str(target), target, **target.options)
             collated.append(action)
     return collated
コード例 #15
0
ファイル: test_action.py プロジェクト: stbenjam/gofer
 def test_name(self, is_method):
     # method
     is_method.return_value = True
     target = Mock(im_class='KL', __name__='bar')
     action = Action(target, hours=24)
     self.assertEqual(action.name(), 'KL.bar()')
     # function
     is_method.return_value = False
     target = Mock(__module__='MOD', __name__='bar')
     action = Action(target, hours=24)
     self.assertEqual(action.name(), 'MOD.bar()')