def test_OsDetect():
    from rospkg.os_detect import OsDetect    
    detect = OsDetect()
    try:
        detect.get_detector('fake')
        assert False, "should raise"
    except KeyError: pass
def test_OsDetect_ROS_OVERRIDE():
    from rospkg.os_detect import OsDetect
    detect = OsDetect([('TrueOs', TrueOs())])
    env = {'ROS_OS_OVERRIDE': 'arch'}
    assert detect.detect_os(env=env) == ('arch', '', ''), detect.detect_os(env=env)
    env = {'ROS_OS_OVERRIDE': 'fubuntu:04.10'}
    assert detect.detect_os(env=env) == ('fubuntu', '04.10', '')
    env = {'ROS_OS_OVERRIDE': 'fubuntu:04.10:opaque'}
    assert detect.detect_os(env=env) == ('fubuntu', '04.10', 'opaque')
示例#3
0
def test_OsDetect_single():
    # test each method twice with new instance b/c of caching
    from rospkg.os_detect import OsDetect
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "TrueOs" == detect.get_name()
    assert "TrueOs" == detect.get_name()
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "os_version" == detect.get_version()
    assert "os_version" == detect.get_version()
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "os_codename" == detect.get_codename()
    assert "os_codename" == detect.get_codename()

    detect = OsDetect([('TrueOs', TrueOs())])
    assert isinstance(detect.get_detector(), TrueOs)
    assert isinstance(detect.get_detector('TrueOs'), TrueOs)
示例#4
0
def test_ubuntu():
    from rospkg.os_detect import OsDetect, OsNotDetected

    os_detector = OsDetect()
    detect = os_detector.get_detector('ubuntu')
    detect.lsb_info = ('Ubuntu', '10.04', 'lucid')

    assert detect.get_version() == '10.04', detect.get_version()
    assert detect.get_codename() == 'lucid', detect.get_codename()

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected:
            pass
        try:
            detect.get_codename()
            assert False
        except OsNotDetected:
            pass
def test_OsDetect_nomatch():
    from rospkg.os_detect import OsDetect, OsNotDetected
    detect = OsDetect([('Dummy', FalseOs())])
    assert isinstance(detect.get_detector('Dummy'), FalseOs)
    try:
        detect.get_name()
        assert False
    except OsNotDetected: pass
    try:
        detect.get_version()
        assert False
    except OsNotDetected: pass
    try:
        detect.get_detector()
        assert False
    except OsNotDetected: pass
def test_ubuntu():
    import rospkg.os_detect
    from rospkg.os_detect import LsbDetect, OsDetect, OsNotDetected
    test_dir = os.path.join(get_test_dir(), 'ubuntu')
    rospkg.os_detect._lsb_release = os.path.join(test_dir, 'lsb_release')
    detect = OsDetect().get_detector('ubuntu')
    assert detect.is_os()
    assert detect.get_version() == '10.04'
    assert detect.get_codename() == 'lucid'

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected: pass
        try:
            detect.get_codename()
            assert False
        except OsNotDetected: pass
示例#7
0
def test_tripwire_freebsd():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('freebsd')
示例#8
0
def test_tripwire_fedora():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('fedora')
示例#9
0
def test_tripwire_opensuse():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('opensuse')
示例#10
0
def test_tripwire_osx():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('osx')
示例#11
0
def test_OsDetect_single():
    # test each method twice with new instance b/c of caching
    from rospkg.os_detect import OsDetect
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "TrueOs" == detect.get_name()
    assert "TrueOs" == detect.get_name()
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "os_version" == detect.get_version()
    assert "os_version" == detect.get_version()
    detect = OsDetect([('TrueOs', TrueOs())])
    assert "os_codename" == detect.get_codename()
    assert "os_codename" == detect.get_codename()

    detect = OsDetect([('TrueOs', TrueOs())])
    assert isinstance(detect.get_detector(), TrueOs)
    assert isinstance(detect.get_detector('TrueOs'), TrueOs)
示例#12
0
def test_tripwire_slackware():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('slackware')
示例#13
0
def test_tripwire_manjaro():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('manjaro')
示例#14
0
def test_InstallerContext_os_installers():
    from rosdep2.installers import InstallerContext, Installer
    from rospkg.os_detect import OsDetect
    detect = OsDetect()
    context = InstallerContext(detect)
    context.verbose = True

    os_key = 'ubuntu'
    try:
        context.get_os_installer_keys(os_key)
        assert False, "should have raised"
    except KeyError:
        pass
    try:
        context.get_default_os_installer_key(os_key)
        assert False, "should have raised"
    except KeyError:
        pass
    try:
        context.add_os_installer_key(os_key, 'fake-key')
        assert False, "should have raised"
    except KeyError:
        pass
    try:
        context.set_default_os_installer_key(os_key, 'fake-key')
        assert False, "should have raised"
    except KeyError:
        pass
    try:
        context.get_default_os_installer_key('bad-os')
        assert False, "should have raised"
    except KeyError:
        pass

    installer_key1 = 'fake1'
    installer_key2 = 'fake2'

    class FakeInstaller(Installer):
        pass

    class FakeInstaller2(Installer):
        pass

    # configure our context with two valid installers
    context.set_installer(installer_key1, FakeInstaller())
    context.set_installer(installer_key2, FakeInstaller2())

    # start adding installers for os_key
    context.add_os_installer_key(os_key, installer_key1)
    assert context.get_os_installer_keys(os_key) == [installer_key1]

    # retest set_default_os_installer_key, now with installer_key not configured on os
    try:
        context.set_default_os_installer_key(os_key, installer_key2)
        assert False, "should have raised"
    except KeyError as e:
        assert 'add_os_installer' in str(e), e

    # now properly add in key2
    context.add_os_installer_key(os_key, installer_key2)
    assert set(context.get_os_installer_keys(os_key)) == set(
        [installer_key1, installer_key2])

    # test default
    assert None == context.get_default_os_installer_key(os_key)
    context.set_default_os_installer_key(os_key, installer_key1)
    assert installer_key1 == context.get_default_os_installer_key(os_key)
    context.set_default_os_installer_key(os_key, installer_key2)
    assert installer_key2 == context.get_default_os_installer_key(os_key)

    # retest set_default_os_installer_key, now with invalid os
    try:
        context.set_default_os_installer_key('bad-os', installer_key1)
        assert False, "should have raised"
    except KeyError:
        pass
示例#15
0
def test_InstallerContext_installers():
    from rosdep2.installers import InstallerContext, Installer
    from rospkg.os_detect import OsDetect
    detect = OsDetect()
    context = InstallerContext(detect)
    context.verbose = True

    key = 'fake-apt'
    try:
        installer = context.get_installer(key)
        assert False, "should have raised: %s" % (installer)
    except KeyError:
        pass

    class Foo:
        pass

    class FakeInstaller(Installer):
        pass

    class FakeInstaller2(Installer):
        pass

    # test TypeError on set_installer
    try:
        context.set_installer(key, 1)
        assert False, "should have raised"
    except TypeError:
        pass
    try:
        context.set_installer(key, Foo())
        assert False, "should have raised"
    except TypeError:
        pass
    try:
        # must be instantiated
        context.set_installer(key, FakeInstaller)
        assert False, "should have raised"
    except TypeError:
        pass

    installer = FakeInstaller()
    installer2 = FakeInstaller2()
    context.set_installer(key, installer)
    assert context.get_installer(key) == installer
    assert context.get_installer_keys() == [key]

    # repeat with same args
    context.set_installer(key, installer)
    assert context.get_installer(key) == installer
    assert context.get_installer_keys() == [key]

    # repeat with new installer
    context.set_installer(key, installer2)
    assert context.get_installer(key) == installer2
    assert context.get_installer_keys() == [key]

    # repeat with new key
    key2 = 'fake-port'
    context.set_installer(key2, installer2)
    assert context.get_installer(key2) == installer2
    assert set(context.get_installer_keys()) == set([key, key2])

    # test installer deletion
    key3 = 'fake3'
    context.set_installer(key3, installer2)
    assert context.get_installer(key3) == installer2
    assert set(context.get_installer_keys()) == set([key, key2, key3])
    context.set_installer(key3, None)
    try:
        context.get_installer(key3)
        assert False
    except KeyError:
        pass
    assert set(context.get_installer_keys()) == set([key, key2])
示例#16
0
def test_OsDetect_register_default_add_detector():
    # test behavior of register_default and add_detector.  Both take
    # precedence over previous detectors, but at different scopes.
    from rospkg.os_detect import OsDetect
    o1 = TrueOs()
    o2 = TrueOs2()
    key = 'TrueOs'
    detect = OsDetect([(key, o1)])

    assert detect.get_detector(key) == o1
    detect.register_default(key, o2)
    assert detect.get_detector(key) == o1
    detect.add_detector(key, o2)
    assert detect.get_detector(key) == o2

    detect = OsDetect()
    assert detect.get_detector(key) == o2
    detect.add_detector(key, o1)
    assert detect.get_detector(key) == o1

    # restore precendence of o1 in default list
    detect.register_default(key, o1)
    detect = OsDetect()
    assert detect.get_detector(key) == o1
示例#17
0
def test_tripwire_slackware():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('slackware')
示例#18
0
def test_tripwire_centos():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('centos')
示例#19
0
def test_tripwire_freebsd():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('freebsd')
示例#20
0
def test_tripwire_ubuntu():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('ubuntu')
示例#21
0
def test_OsDetect_register_default_add_detector():
    # test behavior of register_default and add_detector.  Both take
    # precedence over previous detectors, but at different scopes.
    from rospkg.os_detect import OsDetect
    o1 = TrueOs()
    o2 = TrueOs2()
    key = 'TrueOs'
    detect = OsDetect([(key, o1)])

    assert detect.get_detector(key) == o1
    detect.register_default(key, o2)
    assert detect.get_detector(key) == o1
    detect.add_detector(key, o2)
    assert detect.get_detector(key) == o2

    detect = OsDetect()
    assert detect.get_detector(key) == o2
    detect.add_detector(key, o1)
    assert detect.get_detector(key) == o1

    # restore precendence of o1 in default list
    detect.register_default(key, o1)
    detect = OsDetect()
    assert detect.get_detector(key) == o1
示例#22
0
def test_tripwire_debian():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('debian')
示例#23
0
def test_tripwire_debian():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('debian')
示例#24
0
def test_tripwire_osx():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('osx')
示例#25
0
def test_tripwire_arch():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('arch')
示例#26
0
def test_tripwire_arch():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('arch')
示例#27
0
def test_tripwire_gentoo():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('gentoo')
示例#28
0
def test_tripwire_opensuse():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('opensuse')
示例#29
0
def test_tripwire_rhel():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('rhel')
示例#30
0
def test_tripwire_gentoo():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('gentoo')
示例#31
0
def test_tripwire_fedora():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('fedora')
示例#32
0
def test_tripwire_rhel():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('rhel')
示例#33
0
def test_tripwire_ubuntu():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('ubuntu')
示例#34
0
def test_tripwire_manjaro():
    from rospkg.os_detect import OsDetect
    os_detect = OsDetect()
    os_detect.get_detector('manjaro')