예제 #1
0
def test_module_requires_option(caplog):
    """Test that modules are disabled when they don't satisfy `requires`."""
    # Simple module that satisfies the requirements
    does_satisfy_requiremnets = {
        'enabled': True,
        'requires': {
            'shell': 'command -v cd'
        },
    }
    assert Module.valid_module(
        name='satisfies',
        config=does_satisfy_requiremnets,
        requires_timeout=1,
        requires_working_directory=Path('/'),
    )

    # Simple module that does not satisfy requirements
    does_not_satisfy_requirements = {
        'requires': {
            'shell': 'command -v does_not_exist'
        },
    }
    assert not Module.valid_module(
        name='does_not_satisfy',
        config=does_not_satisfy_requirements,
        requires_timeout=1,
        requires_working_directory=Path('/'),
    )
    assert (
        'astrality.module',
        logging.WARNING,
        '[module/does_not_satisfy] Module requirements: '
        'Unsuccessful command: "command -v does_not_exist", !',
    ) in caplog.record_tuples

    # Test failing one of many requirements
    does_not_satisfy_one_requirement = {
        'requires': [
            {
                'shell': 'command -v cd'
            },
            {
                'shell': 'command -v does_not_exist'
            },
        ],
    }
    caplog.clear()
    assert not Module.valid_module(
        name='does_not_satisfy',
        config=does_not_satisfy_one_requirement,
        requires_timeout=1,
        requires_working_directory=Path('/'),
    )
    assert (
        'astrality.module',
        logging.WARNING,
        RegexCompare(
            r'\[module/does_not_satisfy\] Module requirements: .+ '
            'Unsuccessful command: "command -v does_not_exist", !', ),
    ) in caplog.record_tuples
예제 #2
0
 def test_valid_class_section_method_with_valid_section(
     self,
     valid_module_section,
 ):
     assert Module.valid_module(
         name='test',
         config=valid_module_section,
         requires_timeout=2,
         requires_working_directory=Path('/'),
     ) is True
예제 #3
0
 def test_valid_class_section_method_with_disabled_module_section(self):
     disabled_module_section = {
         'enabled': False,
         'on_startup': {'run': ['test']},
         'on_event': {'run': ['']},
         'on_exit': {'run': ['whatever']},
     }
     assert Module.valid_module(
         name='test',
         config=disabled_module_section,
         requires_timeout=2,
         requires_working_directory=Path('/'),
     ) is False