Beispiel #1
0
def test_LsbDetect():
    from rospkg.os_detect import LsbDetect, OsNotDetected

    # test non-match
    detect = LsbDetect('bad')
    assert not detect.is_os()
    try:
        detect.get_version()
        assert False
    except OsNotDetected:
        pass
    try:
        detect.get_codename()
        assert False
    except OsNotDetected:
        pass

    # test match
    import platform
    platform.linux_distribution = mock.Mock()
    platform.linux_distribution.return_value = ('Ubuntu', '10.04', 'lucid')
    platform.dist = mock.Mock()
    platform.dist.return_value = ('Ubuntu', '10.04', 'lucid')

    detect = LsbDetect('Ubuntu')
    assert detect.is_os(), "should be Ubuntu"
    assert detect.get_codename() == 'lucid', detect.get_codename()

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected:
            pass
def test_LsbDetect():
    from rospkg.os_detect import LsbDetect, OsNotDetected

    # test non-match
    detect = LsbDetect('bad')
    assert not detect.is_os()
    try:
        detect.get_version()
        assert False
    except OsNotDetected:
        pass
    try:
        detect.get_codename()
        assert False
    except OsNotDetected:
        pass

    # test match
    # to be removed after Ubuntu Xenial is out of support
    import sys
    if sys.version_info >= (3, 8):
        import distro
    else:
        import platform as distro

    distro.linux_distribution = mock.Mock()
    distro.linux_distribution.return_value = ('Ubuntu', '10.04', 'lucid')
    distro.dist = mock.Mock()
    distro.dist.return_value = ('Ubuntu', '10.04', 'lucid')

    detect = LsbDetect('Ubuntu')
    assert detect.is_os(), "should be Ubuntu"
    assert detect.get_codename() == 'lucid', detect.get_codename()

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected:
            pass
Beispiel #3
0
def test_LsbDetect():
    from rospkg.os_detect import LsbDetect, OsNotDetected

    # test non-match
    detect = LsbDetect('bad')
    assert not detect.is_os()
    try:
        detect.get_version()
        assert False
    except OsNotDetected:
        pass
    try:
        detect.get_codename()
        assert False
    except OsNotDetected:
        pass

    # test match
    # to be removed after Ubuntu Xenial is out of support
    import sys
    if sys.version_info >= (3, 8):
        import distro
    else:
        import platform as distro

    # Mock different interfaces based on the module used.
    if distro.__name__ == 'distro':
        distro.id = Mock()
        distro.id.return_value = 'Ubuntu'
        distro.version = Mock()
        distro.version.return_value = '10.04'
        distro.codename = Mock()
        distro.codename.return_value = 'lucid'
    elif hasattr(distro, 'linux_distribution'):
        distro.linux_distribution = Mock()
        distro.linux_distribution.return_value = ('Ubuntu', '10.04', 'lucid')
    elif hasattr(distro, 'dist'):
        distro.dist = Mock()
        distro.dist.return_value = ('Ubuntu', '10.04', 'lucid')

    detect = LsbDetect('Ubuntu')
    assert detect.is_os(), "should be Ubuntu"
    assert detect.get_codename() == 'lucid', detect.get_codename()

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected:
            pass
Beispiel #4
0
def test_LsbDetect():
    from rospkg.os_detect import LsbDetect, OsNotDetected

    # test non-match
    detect = LsbDetect('bad')
    assert not detect.is_os()
    try:
        detect.get_version()
        assert False
    except OsNotDetected:
        pass
    try:
        detect.get_codename()
        assert False
    except OsNotDetected:
        pass

    # test match
    import platform
    platform.linux_distribution = mock.Mock()
    platform.linux_distribution.return_value = ('Ubuntu', '10.04', 'lucid')
    platform.dist = mock.Mock()
    platform.dist.return_value = ('Ubuntu', '10.04', 'lucid')

    detect = LsbDetect('Ubuntu')
    assert detect.is_os(), "should be Ubuntu"
    assert detect.get_codename() == 'lucid', detect.get_codename()

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected:
            pass
def test_LsbDetect():
    import rospkg.os_detect
    from rospkg.os_detect import LsbDetect, OsDetect, OsNotDetected, lsb_get_os

    # test non-match
    detect = LsbDetect('bad')
    assert not detect.is_os()
    try:
        detect.get_version()
        assert False
    except OsNotDetected: pass
    try:
        detect.get_codename()
        assert False
    except OsNotDetected: pass

    # test match
    test_dir = os.path.join(get_test_dir(), 'ubuntu')
    rospkg.os_detect._lsb_release = os.path.join(test_dir, 'lsb_release')

    detect = LsbDetect('Ubuntu')
    assert detect.is_os(), lsb_get_os()
    assert detect.get_codename() == 'lucid'

    # test freely
    if not detect.is_os():
        try:
            detect.get_version()
            assert False
        except OsNotDetected: pass