本文整理汇总了Python中tests.test_helpers.fixture_path函数的典型用法代码示例。如果您正苦于以下问题:Python fixture_path函数的具体用法?Python fixture_path怎么用?Python fixture_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fixture_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_change_data_path_after_creation
def test_can_change_data_path_after_creation(self):
original_path = test_helpers.fixture_path('unicode.txt')
new_path = test_helpers.fixture_path('foo.txt')
resource_dict = {
'path': original_path
}
resource = datapackage.Resource.load(resource_dict)
resource.descriptor['path'] = new_path
assert resource.data == b'foo\n'
示例2: test_generates_unique_filenames_for_unnamed_resources
def test_generates_unique_filenames_for_unnamed_resources(self, tmpfile):
metadata = {
'name': 'proverbs',
'resources': [
{'path': test_helpers.fixture_path('unicode.txt')},
{'path': test_helpers.fixture_path('foo.txt')}
]
}
schema = {}
dp = datapackage.DataPackage(metadata, schema)
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
files = z.namelist()
assert sorted(set(files)) == sorted(files)
示例3: test_remote_data_path_returns_none_if_theres_no_remote_data
def test_remote_data_path_returns_none_if_theres_no_remote_data(self):
resource_dict = {
'data': 'foo',
'path': test_helpers.fixture_path('unicode.txt'),
}
resource = datapackage.Resource.load(resource_dict)
assert resource.remote_data_path is None
示例4: test_init_raises_if_path_is_a_bad_json
def test_init_raises_if_path_is_a_bad_json(self):
bad_json = test_helpers.fixture_path('bad_json.json')
with pytest.raises(datapackage.exceptions.DataPackageException) as excinfo:
datapackage.DataPackage(bad_json)
message = str(excinfo.value)
assert 'Unable to parse JSON' in message
assert 'line 2 column 5 (char 6)' in message
示例5: test_load_accepts_absolute_paths
def test_load_accepts_absolute_paths(self):
path = test_helpers.fixture_path('foo.txt')
resource_dict = {
'path': path,
}
resource = datapackage.Resource.load(resource_dict)
assert resource.data == b'foo\n'
示例6: test_load_binary_data
def test_load_binary_data(self):
resource_dict = {
'path': test_helpers.fixture_path('image.gif'),
}
resource = datapackage.Resource.load(resource_dict)
with open(resource_dict['path'], 'rb') as f:
assert resource.data == f.read()
示例7: test_load_prefers_loading_local_data_over_url
def test_load_prefers_loading_local_data_over_url(self):
httpretty.HTTPretty.allow_net_connect = False
resource_dict = {
'path': test_helpers.fixture_path('foo.txt'),
'url': 'http://someplace.com/inexistent-file.txt',
}
resource = datapackage.Resource.load(resource_dict)
assert resource.data == b'foo\n'
示例8: test_works_with_resources_with_relative_paths
def test_works_with_resources_with_relative_paths(self, tmpfile):
path = test_helpers.fixture_path(
'datapackage_with_foo.txt_resource.json'
)
dp = datapackage.DataPackage(path)
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
assert len(z.filelist) == 2
示例9: test_local_data_path
def test_local_data_path(self, datapackage_zip):
dp = datapackage.DataPackage(datapackage_zip)
assert dp.resources[0].local_data_path is not None
with open(test_helpers.fixture_path('foo.txt')) as data_file:
with open(dp.resources[0].local_data_path) as local_data_file:
assert local_data_file.read() == data_file.read()
示例10: test_with_local_resources_with_existent_path_isnt_safe
def test_with_local_resources_with_existent_path_isnt_safe(self):
metadata = {
'resources': [
{'path': test_helpers.fixture_path('foo.txt')},
]
}
dp = datapackage.DataPackage(metadata, {})
assert not dp.safe()
示例11: test_local_data_path_returns_the_absolute_path
def test_local_data_path_returns_the_absolute_path(self):
base_path = test_helpers.fixture_path('')
path = os.path.join(base_path, '..', 'fixtures', 'unicode.txt')
resource_dict = {
'path': path,
}
resource = datapackage.Resource.load(resource_dict)
abs_path = os.path.join(base_path, 'unicode.txt')
assert resource.local_data_path == abs_path
示例12: test_load_accepts_relative_paths
def test_load_accepts_relative_paths(self):
filename = 'foo.txt'
base_path = os.path.dirname(
test_helpers.fixture_path(filename)
)
resource_dict = {
'path': filename,
}
resource = datapackage.Resource.load(resource_dict, base_path)
assert resource.data == b'foo\n'
示例13: datapackage_zip
def datapackage_zip(tmpfile):
metadata = {
'name': 'proverbs',
'resources': [
{'path': test_helpers.fixture_path('foo.txt')},
]
}
dp = datapackage.DataPackage(metadata)
dp.save(tmpfile)
return tmpfile
示例14: _create_resource_file_with
def _create_resource_file_with(self, fixture):
path = test_helpers.fixture_path(fixture)
with open(path, 'rb') as f:
body = f.read()
url = 'http://www.someplace.com/{fixture}'.format(fixture=fixture)
httpretty.register_uri(httpretty.GET,
url,
body=body)
return RemoteResourceFile(url)
示例15: test_local_resource_with_absolute_path_is_loaded
def test_local_resource_with_absolute_path_is_loaded(self):
path = test_helpers.fixture_path('foo.txt')
metadata = {
'resources': [
{'path': path},
],
}
dp = datapackage.DataPackage(metadata)
assert len(dp.resources) == 1
assert dp.resources[0].data == b'foo\n'