import os here = os.path.dirname(__file__) from obconfloader import load_ob from altloader import fail_load_ob def test_file(): filename = os.path.join(here, 'example.py') obj, group = load_ob('file %s' % filename) assert group is None assert obj.location == here assert obj.os is os obj, group = load_ob('file %s:location' % filename) assert obj == here assert group is None obj, group = load_ob('file %s [some.interface]' % filename) assert group == 'some.interface' exc = fail_load_ob('file %s [some.interface]' % filename, groups=['another.interface']) assert 'some.interface' in str(exc) and 'another.interface' in str(exc) exc = fail_load_ob('file /does/not/exists.ini') assert 'exists.ini' in str(exc) and 'does not exist' in str(exc) exc = fail_load_ob('file /') assert 'is a directory' in str(exc) exc = fail_load_ob('file %s' % os.path.join(here, 'invalid-python.example')) assert 'SyntaxError' in str(exc) assert 'invalid-python.example' in str(exc) assert 'invalid syntax' in str(exc)