def test_update_sources_list():
    from rosdep2.sources_list import update_sources_list, InvalidData, compute_filename_hash, PICKLE_CACHE_EXT
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    try:
        from urllib.request import pathname2url
    except ImportError:
        from urllib import pathname2url
    sources_list_dir = get_test_dir()
    index_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'rosdistro', 'index.yaml'))
    index_url = 'file://' + pathname2url(index_path)
    os.environ['ROSDISTRO_INDEX_URL'] = index_url
    tempdir = tempfile.mkdtemp()
    # use a subdirectory of test dir to make sure rosdep creates the necessary substructure
    tempdir = os.path.join(tempdir, 'newdir')

    errors = []

    def error_handler(loc, e):
        errors.append((loc, e))

    retval = update_sources_list(sources_list_dir=sources_list_dir,
                                 sources_cache_dir=tempdir,
                                 error_handler=error_handler)
    assert retval
    assert len(retval) == 2, retval
    # one of our sources is intentionally bad, this should be a softfail
    assert len(errors) == 1, errors
    assert errors[0][
        0].url == 'https://badhostname.willowgarage.com/rosdep.yaml'

    source0, path0 = retval[0]
    assert source0.origin.endswith('20-default.list'), source0
    hash1 = compute_filename_hash(GITHUB_URL)
    hash2 = compute_filename_hash(BADHOSTNAME_URL)
    filepath = os.path.join(tempdir, hash1)
    assert filepath == path0, '%s vs %s' % (filepath, path0)
    with open(filepath + PICKLE_CACHE_EXT, 'rb') as f:
        data = pickle.loads(f.read())
        assert 'cmake' in data

    # verify that cache index exists. contract specifies that even
    # failed downloads are specified in the index, just in case old
    # download data is present.
    with open(os.path.join(tempdir, 'index'), 'r') as f:
        index = f.read().strip()
    expected = "#autogenerated by rosdep, do not edit. use 'rosdep update' instead\n"\
               'yaml %s \n'\
               'yaml %s python\n'\
               'yaml %s ubuntu' % (GITHUB_URL, GITHUB_PYTHON_URL, BADHOSTNAME_URL)
    assert expected == index, '\n[%s]\nvs\n[%s]' % (expected, index)
Esempio n. 2
0
def test_update_sources_list():
    from rosdep2.sources_list import update_sources_list, InvalidData, compute_filename_hash, PICKLE_CACHE_EXT
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    try:
        from urllib.request import pathname2url
    except ImportError:
        from urllib import pathname2url
    sources_list_dir = get_test_dir()
    index_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'rosdistro', 'index.yaml'))
    index_url = 'file://' + pathname2url(index_path)
    os.environ['ROSDISTRO_INDEX_URL'] = index_url
    tempdir = tempfile.mkdtemp()
    # use a subdirectory of test dir to make sure rosdep creates the necessary substructure
    tempdir = os.path.join(tempdir, 'newdir')

    errors = []

    def error_handler(loc, e):
        errors.append((loc, e))
    retval = update_sources_list(sources_list_dir=sources_list_dir,
                                 sources_cache_dir=tempdir, error_handler=error_handler)
    assert retval
    assert len(retval) == 2, retval
    # one of our sources is intentionally bad, this should be a softfail
    assert len(errors) == 1, errors
    assert errors[0][0].url == 'https://badhostname.willowgarage.com/rosdep.yaml'

    source0, path0 = retval[0]
    assert source0.origin.endswith('20-default.list'), source0
    hash1 = compute_filename_hash(GITHUB_URL)
    hash2 = compute_filename_hash(BADHOSTNAME_URL)
    filepath = os.path.join(tempdir, hash1)
    assert filepath == path0, '%s vs %s' % (filepath, path0)
    with open(filepath + PICKLE_CACHE_EXT, 'rb') as f:
        data = pickle.loads(f.read())
        assert 'cmake' in data

    # verify that cache index exists. contract specifies that even
    # failed downloads are specified in the index, just in case old
    # download data is present.
    with open(os.path.join(tempdir, 'index'), 'r') as f:
        index = f.read().strip()
    expected = "#autogenerated by rosdep, do not edit. use 'rosdep update' instead\n"\
               'yaml %s \n'\
               'yaml %s python\n'\
               'yaml %s ubuntu' % (GITHUB_URL, GITHUB_PYTHON_URL, BADHOSTNAME_URL)
    assert expected == index, '\n[%s]\nvs\n[%s]' % (expected, index)
Esempio n. 3
0
def test_write_cache_file():
    from rosdep2.sources_list import write_cache_file, compute_filename_hash
    tempdir = tempfile.mkdtemp()

    filepath = write_cache_file(tempdir, 'foo', {'data': 1})
    computed_path = os.path.join(tempdir, compute_filename_hash('foo'))
    assert os.path.samefile(filepath, computed_path)
    with open(filepath, 'r') as f:
        assert {'data': 1} == yaml.load(f.read())
Esempio n. 4
0
def test_write_cache_file():
    from rosdep2.sources_list import write_cache_file, compute_filename_hash
    tempdir = tempfile.mkdtemp()
    
    filepath = write_cache_file(tempdir, 'foo', {'data': 1})
    computed_path = os.path.join(tempdir, compute_filename_hash('foo'))
    assert os.path.samefile(filepath, computed_path)
    with open(filepath, 'r') as f:
        assert {'data': 1} == yaml.load(f.read())
def test_write_cache_file():
    from rosdep2.sources_list import write_cache_file, compute_filename_hash, PICKLE_CACHE_EXT
    import cPickle
    tempdir = tempfile.mkdtemp()
    
    filepath = write_cache_file(tempdir, 'foo', {'data': 1})  + PICKLE_CACHE_EXT
    computed_path = os.path.join(tempdir, compute_filename_hash('foo')) + PICKLE_CACHE_EXT
    assert os.path.samefile(filepath, computed_path)
    with open(filepath, 'r') as f:
        assert {'data': 1} == cPickle.loads(f.read())
Esempio n. 6
0
def test_update_sources_list():
    from rosdep2.sources_list import update_sources_list, InvalidData, compute_filename_hash
    sources_list_dir = get_test_dir()
    tempdir = tempfile.mkdtemp()
    # use a subdirectory of test dir to make sure rosdep creates the necessary substructure
    tempdir = os.path.join(tempdir, 'newdir')

    errors = []

    def error_handler(loc, e):
        errors.append((loc, e))

    retval = update_sources_list(sources_list_dir=sources_list_dir,
                                 sources_cache_dir=tempdir,
                                 error_handler=error_handler)
    assert retval
    assert len(retval) == 2, retval
    # one of our sources is intentionally bad, this should be a softfail
    assert len(errors) == 1, errors
    assert errors[0][
        0].url == 'https://badhostname.willowgarage.com/rosdep.yaml'

    source0, path0 = retval[0]
    assert source0.origin.endswith('20-default.list'), source0
    hash1 = compute_filename_hash(GITHUB_URL)
    hash2 = compute_filename_hash(BADHOSTNAME_URL)
    filepath = os.path.join(tempdir, hash1)
    assert filepath == path0, "%s vs %s" % (filepath, path0)
    with open(filepath, 'r') as f:
        data = yaml.load(f)
        assert 'cmake' in data

    # verify that cache index exists. contract specifies that even
    # failed downloads are specified in the index, just in case old
    # download data is present.
    with open(os.path.join(tempdir, 'index'), 'r') as f:
        index = f.read().strip()
    expected = """#autogenerated by rosdep, do not edit. use 'rosdep update' instead
yaml %s 
yaml %s python
yaml %s ubuntu""" % (GITHUB_URL, GITHUB_PYTHON_URL, BADHOSTNAME_URL)
    assert expected == index, "\n[%s]\nvs\n[%s]" % (expected, index)
Esempio n. 7
0
def test_write_cache_file():
    from rosdep2.sources_list import write_cache_file, compute_filename_hash, PICKLE_CACHE_EXT
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    tempdir = tempfile.mkdtemp()

    filepath = write_cache_file(tempdir, 'foo', {'data': 1}) + PICKLE_CACHE_EXT
    computed_path = os.path.join(tempdir, compute_filename_hash('foo')) + PICKLE_CACHE_EXT
    assert os.path.samefile(filepath, computed_path)
    with open(filepath, 'rb') as f:
        assert {'data': 1} == pickle.loads(f.read())
def test_update_sources_list():
    from rosdep2.sources_list import update_sources_list, InvalidData, compute_filename_hash, PICKLE_CACHE_EXT
    import cPickle
    sources_list_dir=get_test_dir()
    tempdir = tempfile.mkdtemp()
    # use a subdirectory of test dir to make sure rosdep creates the necessary substructure
    tempdir = os.path.join(tempdir, 'newdir')

    errors = []
    def error_handler(loc, e):
        errors.append((loc, e))
    retval = update_sources_list(sources_list_dir=sources_list_dir,
                                 sources_cache_dir=tempdir, error_handler=error_handler)
    assert retval
    assert len(retval) == 2, retval
    # one of our sources is intentionally bad, this should be a softfail
    assert len(errors) == 1, errors
    assert errors[0][0].url == 'https://badhostname.willowgarage.com/rosdep.yaml'

    source0, path0 = retval[0]
    assert source0.origin.endswith('20-default.list'), source0
    hash1 = compute_filename_hash(GITHUB_URL)
    hash2 = compute_filename_hash(BADHOSTNAME_URL)
    filepath = os.path.join(tempdir, hash1)
    assert filepath == path0, "%s vs %s"%(filepath, path0)
    with open(filepath+PICKLE_CACHE_EXT, 'r') as f:
        data = cPickle.loads(f.read())
        assert 'cmake' in data

    # verify that cache index exists. contract specifies that even
    # failed downloads are specified in the index, just in case old
    # download data is present.
    with open(os.path.join(tempdir, 'index'), 'r') as f:
        index = f.read().strip()
    expected = """#autogenerated by rosdep, do not edit. use 'rosdep update' instead
yaml %s 
yaml %s python
yaml %s ubuntu"""%(GITHUB_URL, GITHUB_PYTHON_URL, BADHOSTNAME_URL)
    assert expected == index, "\n[%s]\nvs\n[%s]"%(expected, index)