def test_config(): """Test vispy config methods and file downloading""" assert_raises(TypeError, config.update, data_path=dict()) assert_raises(KeyError, config.update, foo='bar') # bad key data_dir = op.join(temp_dir, 'data') assert_raises(IOError, set_data_dir, data_dir) # didn't say to create orig_val = os.environ.get('_VISPY_CONFIG_TESTING', None) os.environ['_VISPY_CONFIG_TESTING'] = 'true' try: assert_raises(IOError, set_data_dir, data_dir) # doesn't exist yet set_data_dir(data_dir, create=True, save=True) assert_equal(config['data_path'], data_dir) config['data_path'] = data_dir print(config) # __repr__ load_data_file('CONTRIBUTING.txt') fid = open(op.join(data_dir, 'test-faked.txt'), 'w') fid.close() load_data_file('test-faked.txt') # this one shouldn't download assert_raises(RuntimeError, load_data_file, 'foo-nonexist.txt') save_config() finally: if orig_val is not None: os.environ['_VISPY_CONFIG_TESTING'] = orig_val else: del os.environ['_VISPY_CONFIG_TESTING']
def test_config(): """Test vispy config methods and file downloading""" assert_raises(TypeError, config.update, data_path=dict()) assert_raises(KeyError, config.update, foo="bar") # bad key data_dir = op.join(temp_dir, "data") assert_raises(IOError, set_data_dir, data_dir) # didn't say to create orig_val = os.environ.get("_VISPY_CONFIG_TESTING", None) os.environ["_VISPY_CONFIG_TESTING"] = "true" try: assert_raises(IOError, set_data_dir, data_dir) # doesn't exist yet set_data_dir(data_dir, create=True, save=True) assert_equal(config["data_path"], data_dir) config["data_path"] = data_dir print(config) # __repr__ load_data_file("CONTRIBUTING.txt") fid = open(op.join(data_dir, "test-faked.txt"), "w") fid.close() load_data_file("test-faked.txt") # this one shouldn't download assert_raises(RuntimeError, load_data_file, "foo-nonexist.txt") save_config() finally: if orig_val is not None: os.environ["_VISPY_CONFIG_TESTING"] = orig_val else: del os.environ["_VISPY_CONFIG_TESTING"]
def test_config(): """Test vispy config methods and file downloading""" assert_raises(TypeError, config.update, data_path=dict()) assert_raises(KeyError, config.update, foo='bar') # bad key data_dir = op.join(temp_dir, 'data') assert_raises(IOError, set_data_dir, data_dir) # didn't say to create orig_val = os.environ.get('_VISPY_CONFIG_TESTING', None) os.environ['_VISPY_CONFIG_TESTING'] = 'true' try: assert_raises(IOError, set_data_dir, data_dir) # doesn't exist yet set_data_dir(data_dir, create=True, save=True) assert_equal(config['data_path'], data_dir) config['data_path'] = data_dir print(config) # __repr__ get_data_file('CONTRIBUTING.txt') fid = open(op.join(data_dir, 'test-faked.txt'), 'w') fid.close() get_data_file('test-faked.txt') # this one shouldn't download assert_raises(RuntimeError, get_data_file, 'foo-nonexist.txt') save_config() finally: if orig_val is not None: os.environ['_VISPY_CONFIG_TESTING'] = orig_val else: del os.environ['_VISPY_CONFIG_TESTING']