Beispiel #1
0
    def __init__(self, fully_qualified_name: str,
                 schema_loader: SchemaLoader) -> None:
        super().__init__(fully_qualified_name, schema_loader,
                         self.ATTRIBUTE_AGGREGATES)

        self.version = self._spec.get(self.ATTRIBUTE_VERSION, None)
        self.import_list = self._spec.get(self.ATTRIBUTE_IMPORT, [])
        self.schema_context = SchemaContext(self.import_list)
Beispiel #2
0
def test_import_module_and_identifier_with_alias():
    spec = [{'Module': 'dateutil', 'Identifiers': ['parser as my_func']}]
    schema_context = SchemaContext(spec)
    context = schema_context.context

    assert not context.local_context
    assert context.global_context

    from dateutil import parser
    assert context.global_context['my_func'] == parser
Beispiel #3
0
def test_import_just_module_with_alias():
    spec = [{'Module': 'dateutil as my_mod'}]
    schema_context = SchemaContext(spec)
    context = schema_context.context

    assert not context.local_context
    assert context.global_context

    import dateutil
    assert context.global_context['my_mod'] == dateutil
Beispiel #4
0
def test_import_module_and_multiple_identifiers():
    spec = [{'Module': 'dateutil', 'Identifiers': ['parser', 'tz']}]
    schema_context = SchemaContext(spec)
    context = schema_context.context

    assert not context.local_context
    assert context.global_context

    from dateutil import parser
    from dateutil import tz
    assert context.global_context['parser'] == parser
    assert context.global_context['tz'] == tz
Beispiel #5
0
def test_import_module_and_identifier_error():
    spec = [{'Module': 'dateutil', 'Identifiers': ['unknown_func']}]
    schema_context = SchemaContext(spec)
    with pytest.raises(ImportError,
                       match='cannot import name \'unknown_func\''):
        assert schema_context.context
Beispiel #6
0
def test_import_just_module_error():
    spec = [{'Module': 'unknown_module'}]
    schema_context = SchemaContext(spec)
    with pytest.raises(ModuleNotFoundError,
                       match='No module named \'unknown_module\''):
        assert schema_context.context
Beispiel #7
0
def test_import_empty():
    schema_context = SchemaContext([])
    context = schema_context.context

    assert not context.local_context
    assert not context.global_context