本文整理汇总了Python中tests.test_helpers.fixture_path函数的典型用法代码示例。如果您正苦于以下问题:Python fixture_path函数的具体用法?Python fixture_path怎么用?Python fixture_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fixture_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:9,代码来源:test_resource.py
示例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)
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:14,代码来源:test_datapackage.py
示例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
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:7,代码来源:test_resource.py
示例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
开发者ID:frictionlessdata,项目名称:datapackage-py,代码行数:7,代码来源:test_datapackage.py
示例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'
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:7,代码来源:test_resource.py
示例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()
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:8,代码来源:test_resource.py
示例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'
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:8,代码来源:test_resource.py
示例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
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:8,代码来源:test_datapackage.py
示例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()
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:8,代码来源:test_datapackage.py
示例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()
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:8,代码来源:test_datapackage.py
示例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
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:9,代码来源:test_resource.py
示例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'
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:10,代码来源:test_resource.py
示例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
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:10,代码来源:test_datapackage.py
示例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)
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:10,代码来源:test_resource_file.py
示例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'
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:10,代码来源:test_datapackage.py
示例16: test_fixes_resources_paths_to_be_relative_to_package
def test_fixes_resources_paths_to_be_relative_to_package(self, tmpfile):
resource_path = test_helpers.fixture_path('unicode.txt')
metadata = {
'name': 'proverbs',
'resources': [
{'name': 'unicode', 'format': 'txt', 'path': resource_path}
]
}
schema = {}
dp = datapackage.DataPackage(metadata, schema)
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
json_string = z.read('datapackage.json').decode('utf-8')
generated_dp_dict = json.loads(json_string)
assert generated_dp_dict['resources'][0]['path'] == 'data/unicode.txt'
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:15,代码来源:test_datapackage.py
示例17: test_generates_filenames_for_named_resources
def test_generates_filenames_for_named_resources(self, tmpfile):
resource_path = test_helpers.fixture_path('unicode.txt')
metadata = {
'name': 'proverbs',
'resources': [
{'name': 'proverbs', 'format': 'TXT', 'path': resource_path},
{'name': 'proverbs_without_format', 'path': resource_path}
]
}
schema = {}
dp = datapackage.DataPackage(metadata, schema)
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
assert 'data/proverbs.txt' in z.namelist()
assert 'data/proverbs_without_format' in z.namelist()
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:15,代码来源:test_datapackage.py
示例18: test_adds_resources_inside_data_subfolder
def test_adds_resources_inside_data_subfolder(self, tmpfile):
resource_path = test_helpers.fixture_path('unicode.txt')
metadata = {
'name': 'proverbs',
'resources': [
{'path': resource_path}
]
}
schema = {}
dp = datapackage.DataPackage(metadata, schema)
dp.save(tmpfile)
with zipfile.ZipFile(tmpfile, 'r') as z:
filename = [name for name in z.namelist()
if name.startswith('data/')]
assert len(filename) == 1
resource_data = z.read(filename[0]).decode('utf-8')
assert resource_data == '万事开头难\n'
开发者ID:elisonghe,项目名称:datapackage-py,代码行数:17,代码来源:test_datapackage.py
示例19: test_load_tsv
def test_load_tsv(self):
resource_dict = {
'path': test_helpers.fixture_path('cities.tsv')
}
resource = TabularResource(resource_dict)
assert resource.data == [
{'Area': '1807.92', 'Name': 'Acrelândia', 'Population': '12538', 'State': 'AC'},
{'Area': '186.53', 'Name': 'Boca da Mata', 'Population': '25776', 'State': 'AL'},
{'Area': '242.62', 'Name': 'Capela', 'Population': '17077', 'State': 'AL'},
{'Area': '6709.66', 'Name': 'Tartarugalzinho', 'Population': '12563', 'State': 'AP'},
{'Area': '837.72', 'Name': 'América Dourada', 'Population': None, 'State': 'BA'},
{'Area': '204.79', 'Name': 'Jijoca de Jericoacoara', 'Population': '17002', 'State': 'CE'},
{'Area': '6953.67', 'Name': 'Cavalcante', 'Population': '9392', 'State': 'GO'},
{'Area': '8258.42', 'Name': 'Centro Novo do Maranhão', 'Population': '17622', 'State': 'MA'},
{'Area': '3651.18', 'Name': 'Ped\\ro G\\omes', 'Population': '7967', 'State': 'MS'},
{'Area': '881.06', 'Name': 'Abadia dos Dourados', 'Population': '6704', 'State': 'MG'},
]
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:18,代码来源:test_resource.py
示例20: test_push_datapackage
def test_push_datapackage(storage):
# Prepare and call
descriptor = helpers.fixture_path('datapackage', 'datapackage.json')
storage.tables = ['data___data'] # Without patch it's a reflection
module.push_datapackage(descriptor=descriptor, backend='backend')
# Assert mocked calls
storage.create.assert_called_with(
['data___data'],
[{'fields': [
{'name': 'id', 'type': 'integer'},
{'name': 'city', 'type': 'string'}]}])
storage.write.assert_called_with('data___data', ANY)
# Assert writen data
data = storage.write.call_args[0][1]
assert list(data) == [
(1, 'London'),
(2, 'Paris'),
]
开发者ID:scls19fr,项目名称:datapackage-py,代码行数:21,代码来源:test_pushpull.py
注:本文中的tests.test_helpers.fixture_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论