def test_valid_class_section_with_wrongly_sized_dict( self, valid_module_section): invalid_module_section = valid_module_section invalid_module_section.update({'module/valid2': {'enabled': True}}) with pytest.raises(RuntimeError): Module.valid_class_section( section=invalid_module_section, requires_timeout=2, requires_working_directory=Path('/'), )
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 = { 'module/satisfies': { 'enabled': True, 'requires': {'shell': 'command -v cd',}, }} assert Module.valid_class_section( section=does_satisfy_requiremnets, requires_timeout=1, requires_working_directory=Path('/'), ) # Simple module that does not satisfy requirements does_not_satisfy_requirements = { 'module/does_not_satisfy': { 'requires': {'shell': 'command -v does_not_exist',}, }} assert not Module.valid_class_section( section=does_not_satisfy_requirements, requires_timeout=1, requires_working_directory=Path('/'), ) assert ( 'astrality', 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 = { 'module/does_not_satisfy': { 'requires': [ {'shell': 'command -v cd',}, {'shell': 'command -v does_not_exist',}, ], }} caplog.clear() assert not Module.valid_class_section( section=does_not_satisfy_one_requirement, requires_timeout=1, requires_working_directory=Path('/'), ) assert ( 'astrality', logging.WARNING, RegexCompare( '\[module/does_not_satisfy\] Module requirements: .+ ' 'Unsuccessful command: "command -v does_not_exist", !', ) ) in caplog.record_tuples
def test_valid_class_section_method_with_valid_section( self, valid_module_section): assert Module.valid_class_section( section=valid_module_section, requires_timeout=2, requires_working_directory=Path('/'), ) == True
def test_valid_class_section_method_with_invalid_section(self): invalid_module_section = { 'context/fonts': { 'some_key': 'some_value', } } assert Module.valid_class_section( section=invalid_module_section, requires_timeout=2, requires_working_directory=Path('/'), ) == False
def test_valid_class_section_method_with_disabled_module_section(self): disabled_module_section = { 'module/disabled_test_module': { 'enabled': False, 'on_startup': { 'run': ['test'] }, 'on_event': { 'run': [''] }, 'on_exit': { 'run': ['whatever'] }, } } assert Module.valid_class_section( section=disabled_module_section, requires_timeout=2, requires_working_directory=Path('/'), ) == False