def test_load_cached_sources_list(): from xylem.sources_list import load_cached_sources_list, update_sources_list tempdir = tempfile.mkdtemp() # test behavior on empty cache assert [] == load_cached_sources_list(sources_cache_dir=tempdir) # pull in cache data sources_list_dir=get_test_dir() retval = update_sources_list(sources_list_dir=sources_list_dir, sources_cache_dir=tempdir, error_handler=None) assert retval # now test with cached data retval = load_cached_sources_list(sources_cache_dir=tempdir) assert len(retval) == 3 source0 = retval[0] source1 = retval[1] source2 = retval[2] # this should be the 'default' source assert 'python' in source1.xylem_data assert not source0.tags # this should be the 'non-existent' source assert source2.xylem_data is None assert source2.tags == ['ubuntu']
def test_update_sources_list(): from xylem.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 xylem 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/xylem.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 xylem, do not edit. use 'xylem 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)
def test_SourcesListLoader_create_default(): from xylem.sources_list import update_sources_list, SourcesListLoader, DataSourceMatcher # create temp dir for holding sources cache tempdir = tempfile.mkdtemp() # pull in cache data sources_list_dir=get_test_dir() retval = update_sources_list(sources_list_dir=sources_list_dir, sources_cache_dir=tempdir, error_handler=None) assert retval # now test with cached data matcher = xylem.sources_list.DataSourceMatcher(['ubuntu', 'lucid']) loader = SourcesListLoader.create_default(matcher, sources_cache_dir=tempdir) assert loader.sources sources0 = loader.sources assert not any([s for s in loader.sources if not matcher.matches(s)]) loader = SourcesListLoader.create_default(matcher, sources_cache_dir=tempdir) assert sources0 == loader.sources # now test with different matcher matcher2 = xylem.sources_list.DataSourceMatcher(['python']) loader2 = SourcesListLoader.create_default(matcher2, sources_cache_dir=tempdir) assert loader2.sources # - should have filtered down to python-only assert sources0 != loader2.sources assert not any([s for s in loader2.sources if not matcher2.matches(s)]) # test API # very simple, always raises RNF try: loader.get_packages('foo') except rospkg.ResourceNotFound: pass try: loader.get_view_key('foo') except rospkg.ResourceNotFound: pass assert [] == loader.get_loadable_resources() all_sources = [x.url for x in loader.sources] assert all_sources == loader.get_loadable_views() # test get_source early to make sure model matches expected try: loader.get_source('foo') assert False, "should have raised" except rospkg.ResourceNotFound: pass s = loader.get_source(GITHUB_URL) assert s.url == GITHUB_URL # get_view_dependencies # - loader doesn't new view name, so assume everything assert all_sources == loader.get_view_dependencies('foo') # - actual views don't depend on anything assert [] == loader.get_view_dependencies(GITHUB_URL) # load_view from xylem.model import xylemDatabase for verbose in [True, False]: xylem_db = xylemDatabase() loader.load_view(GITHUB_URL, xylem_db, verbose=verbose) assert xylem_db.is_loaded(GITHUB_URL) assert [] == xylem_db.get_view_dependencies(GITHUB_URL) entry = xylem_db.get_view_data(GITHUB_URL) assert 'cmake' in entry.xylem_data assert GITHUB_URL == entry.origin # - coverage, repeat loader, should noop loader.load_view(GITHUB_URL, xylem_db)