diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97c70a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.py[cod] +*.egg +*.egg-info +.cache/ +.coverage +.tox +coverage.xml +dist/ +site/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c8b1964 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: python +python: 2.7 +branches: + except: + - gh-pages +env: + - TOX_ENV=py27 +before_install: + - sudo apt-get -qq update +install: + - python -m pip install -U pip + - pip install -U setuptools + - pip install tox + - pip install codecov +script: + - tox -e $TOX_ENV +after_success: + - codecov diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..942652e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ + +# Change Log + +## [Unreleased] +### Added +### Fixed +### Changed +### Deprecated +### Removed +### Security + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..3133152 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include LICENSE +recursive-include facsimile *.txt +recursive-include pytest_filedata *.py +include facsimile/VERSION diff --git a/README.md b/README.md new file mode 100644 index 0000000..6851a4a --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ + +# pytest filedata + +[![PyPI](https://img.shields.io/pypi/v/pytest-filedata.svg?maxAge=3600)](https://pypi.python.org/pypi/pytest-filedata) +[![Travis CI](https://img.shields.io/travis/20c/pytest-filedata.svg?maxAge=3600)](https://travis-ci.org/20c/pytest-filedata) +[![Code Health](https://landscape.io/github/20c/pytest-filedata/master/landscape.svg?style=flat)](https://landscape.io/github/20c/pytest-filedata/master) +[![Codecov](https://img.shields.io/codecov/c/github/20c/pytest-filedata/master.svg?maxAge=3600)](https://codecov.io/github/20c/pytest-filedata) +[![Requires.io](https://img.shields.io/requires/github/20c/pytest-filedata.svg?maxAge=3600)](https://requires.io/github/20c/pytest-filedata/requirements) + +easily load test data from files + +### License + +Copyright 2016 20C, LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this softare except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/facsimile/VERSION b/facsimile/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/facsimile/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/facsimile/requirements-test.txt b/facsimile/requirements-test.txt new file mode 100644 index 0000000..e1b48db --- /dev/null +++ b/facsimile/requirements-test.txt @@ -0,0 +1,5 @@ +codecov>=2.0.5 +coverage>=4.1 +pytest>=2.9.2,<4 +pytest-cov>=2.3,<3 +tox>=2.3.1,<3 diff --git a/facsimile/requirements.txt b/facsimile/requirements.txt new file mode 100644 index 0000000..9c25af8 --- /dev/null +++ b/facsimile/requirements.txt @@ -0,0 +1,2 @@ +decorator>=4, <5 +requests-mock>=1, <2 diff --git a/pytest_filedata/__init__.py b/pytest_filedata/__init__.py new file mode 100644 index 0000000..0a61374 --- /dev/null +++ b/pytest_filedata/__init__.py @@ -0,0 +1,150 @@ + +import collections +from datetime import datetime +import json +import os +import urlparse + +import requests_mock +import decorator + + +test_dir = None + + +def setup_filedata(base_dir, fixture_prefixes=None): + """ + setup filedata with base dir for data + """ + global test_dir + test_dir = base_dir + + +def json_hook(data): + date_keys = ( + 'last_change', + 'last_reboot', + 'last_reconfiguration', + ) + for key in date_keys: + if key in data: + data[key] = datetime.strptime(data[key], "%Y-%m-%dT%H:%M:%S") + return data + + + +class JSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, datetime): + return o.isoformat() + + return json.JSONEncoder.default(self, o) + + +def dumps(data): + return json.dumps(data, cls=JSONEncoder) + + +def load(fobj): + return json.load(fobj, object_hook=json_hook) + + +def loads(data): + return json.loads(data, object_hook=json_hook) + + +class FileTestData(object): + def __init__(self, inp=None, exp=None, filename=None): + self.input = inp + self.expected = exp + self.filename = filename + + def dumps(self, data): + return dumps(data) + + def loads(self, data): + return loads(data) + + +def get_test_files(dirname): + """ + gets a list of files in directory specified by name + """ + if not os.path.isdir(dirname): + raise ValueError("data directory '{}' does not exist".format(dirname)) + path = dirname + "/{}" + return map(path.format, sorted(os.listdir(dirname))) + + +def get_filedata(name): + data = collections.OrderedDict() + dirname = os.path.join(test_dir, *name.split('_')) + + for each in get_test_files(dirname): + fname = os.path.basename(each) + if fname.startswith('.'): + continue + + test_name, ext = os.path.splitext(fname) + data.setdefault(test_name, FileTestData(filename=each)) + + # could setattr + attr = ext[1:] + if ext == '.expected': + with open(each) as fobj: + data[test_name].expected = json.load(fobj, object_hook=json_hook) + else: + with open(each) as fobj: + setattr(data[test_name], attr, fobj.read()) + + return data + + +class RequestData(object): + """ + class to use test data from requests + """ + def __init__(self, prefix): + self.prefix = prefix + adapter = requests_mock.Adapter() + adapter.register_uri(requests_mock.ANY, requests_mock.ANY, text=self.callback) + self.mocker = requests_mock.Mocker(adapter=adapter) + + def callback(self, request, context): + path = urlparse.urlparse(request.url).path + path = os.path.join(test_dir, 'data', self.prefix, path.lstrip('/')) + files = get_test_files(path) + if len(files) != 1: + raise NotImplementedError("Currently there must be only one response file") + + fname = files[0] + + # file extension is status code + context.status_code = int(os.path.splitext(fname)[1].lstrip('.')) + + with open(fname) as fobj: + return fobj.read() + + def __call__(self, func): + def wrapper(*args, **kwargs): + with self.mocker: + # FIXME -- why is the test func arg 0? + func(*args[1:], **kwargs) + + # use decorator because functools.wrap changes the function sig + return decorator.decorator(wrapper, func) + + def __enter__(self): + self.mocker.start() + + def __exit__(self, typ, value, traceback): + self.mocker.stop() + + +def pytest_namespace(): + """Register pytest plugin.""" + return dict( + get_filedata=get_filedata, + RequestData=RequestData, + setup_filedata=setup_filedata, + ) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..c825496 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[metadata] +description-file = README.md + +[wheel] +universal = 1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9e10611 --- /dev/null +++ b/setup.py @@ -0,0 +1,36 @@ + +from setuptools import find_packages, setup + + +version = open('facsimile/VERSION').read().strip() +requirements = open('facsimile/requirements.txt').read().split("\n") +test_requirements = open('facsimile/requirements-test.txt').read().split("\n") + + +setup( + name='pytest_filedata', + version=version, + author='20C', + author_email='code@20c.com', + description='easily load data from files', + long_description='', + license='LICENSE.txt', + classifiers=[ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: Apache Software License', + ], + packages = find_packages(), + include_package_data=True, + url='https://github.com/20c/pytest-filedata', + download_url='https://github.com/20c/pytest-filedata/%s' % version, + + install_requires=requirements, + test_requires=test_requirements, + + zip_safe=True, + entry_points={ + 'pytest11': [ + 'filedata = pytest_filedata', + ], + }, +) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e49d41e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ + +import os +import pytest + + +pytest_plugins = ["pytester"] + +pytest.setup_filedata(os.path.dirname(__file__)) + + +def pytest_generate_tests(metafunc): + for fixture in metafunc.fixturenames: + if fixture.startswith('data_'): + data = pytest.get_filedata(fixture) + metafunc.parametrize(fixture, data.values(), ids=data.keys()) diff --git a/tests/data/json/test0.expected b/tests/data/json/test0.expected new file mode 100644 index 0000000..1173371 --- /dev/null +++ b/tests/data/json/test0.expected @@ -0,0 +1,459 @@ +[ + { + "_id": "5a4a580a0c912af0f37e0c90", + "index": 0, + "guid": "0962bf7e-3740-4e89-9b46-70ae0be4f191", + "isActive": true, + "balance": "$3,133.24", + "picture": "http://placehold.it/32x32", + "age": 33, + "eyeColor": "brown", + "name": { + "first": "Tabatha", + "last": "Burch" + }, + "company": "VERBUS", + "email": "tabatha.burch@verbus.biz", + "phone": "+1 (810) 427-2220", + "address": "777 Pineapple Street, Williamson, West Virginia, 5791", + "about": "Lorem veniam sunt excepteur esse ad consectetur id ut labore. Enim nulla nulla occaecat velit laboris voluptate ut ullamco id culpa amet mollit laboris ad. Laboris qui in officia esse proident minim. Eiusmod cupidatat ipsum enim proident Lorem minim magna nulla ipsum ullamco. Aute nisi labore enim ut officia in esse irure. Voluptate nisi culpa aliquip esse.", + "registered": "Friday, March 7, 2014 12:06 AM", + "latitude": "17.214286", + "longitude": "144.533821", + "tags": [ + "proident", + "proident", + "non", + "do", + "occaecat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wendy Leblanc" + }, + { + "id": 1, + "name": "Evangeline Goodwin" + }, + { + "id": 2, + "name": "Contreras Whitney" + } + ], + "greeting": "Hello, Tabatha! You have 9 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580a765a75a04460ab21", + "index": 1, + "guid": "a1abbb4a-42df-4335-931f-d95118e6ff6d", + "isActive": true, + "balance": "$3,772.41", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Heath", + "last": "Puckett" + }, + "company": "SNACKTION", + "email": "heath.puckett@snacktion.us", + "phone": "+1 (881) 521-2112", + "address": "524 Anchorage Place, Joppa, New York, 2672", + "about": "Do ex ullamco exercitation officia non aliqua ad incididunt et tempor. Duis in irure sunt mollit et anim ex incididunt consequat. Irure do ad in ea ad aliqua do veniam est in quis voluptate.", + "registered": "Saturday, June 14, 2014 1:00 PM", + "latitude": "-61.264717", + "longitude": "-148.845539", + "tags": [ + "dolor", + "ullamco", + "Lorem", + "ad", + "quis" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wood Cooke" + }, + { + "id": 1, + "name": "Molly Henderson" + }, + { + "id": 2, + "name": "Madden Flores" + } + ], + "greeting": "Hello, Heath! You have 9 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580aad9f80006cdf10af", + "index": 2, + "guid": "34eb1a42-c9d6-47a0-bef9-1a39d8c9d3e3", + "isActive": false, + "balance": "$3,246.48", + "picture": "http://placehold.it/32x32", + "age": 26, + "eyeColor": "green", + "name": { + "first": "Morin", + "last": "Copeland" + }, + "company": "DATACATOR", + "email": "morin.copeland@datacator.io", + "phone": "+1 (865) 466-3084", + "address": "716 Ross Street, Healy, South Dakota, 4255", + "about": "Ea mollit do voluptate ipsum. Veniam occaecat sint amet veniam non magna ad dolore esse deserunt sint ut officia. Ea exercitation aute do fugiat reprehenderit qui nostrud dolor amet tempor. Est adipisicing cillum ullamco in deserunt proident qui eiusmod eiusmod veniam elit exercitation non nisi.", + "registered": "Monday, September 21, 2015 1:57 PM", + "latitude": "-38.785254", + "longitude": "-154.992394", + "tags": [ + "duis", + "anim", + "occaecat", + "anim", + "laborum" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Kathie Chase" + }, + { + "id": 1, + "name": "Anne Wong" + }, + { + "id": 2, + "name": "Alexander Lee" + } + ], + "greeting": "Hello, Morin! You have 5 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580af71694d16fed521d", + "index": 3, + "guid": "91778e07-79d1-44f1-9499-f3df9b991d9e", + "isActive": false, + "balance": "$2,269.05", + "picture": "http://placehold.it/32x32", + "age": 34, + "eyeColor": "brown", + "name": { + "first": "Dina", + "last": "Hernandez" + }, + "company": "NAMEGEN", + "email": "dina.hernandez@namegen.co.uk", + "phone": "+1 (890) 467-3197", + "address": "417 Knapp Street, Gouglersville, Palau, 3690", + "about": "Excepteur minim tempor et sint irure adipisicing ex do reprehenderit labore. Est aute ea amet consequat laboris veniam ea tempor amet elit enim. Pariatur sunt laboris tempor ea eu in.", + "registered": "Tuesday, April 29, 2014 8:39 PM", + "latitude": "88.93652", + "longitude": "122.04518", + "tags": [ + "eu", + "nulla", + "mollit", + "adipisicing", + "irure" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Brianna Cochran" + }, + { + "id": 1, + "name": "Herman Mendoza" + }, + { + "id": 2, + "name": "Rose Mcclain" + } + ], + "greeting": "Hello, Dina! You have 6 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580ab638604600c06bc7", + "index": 4, + "guid": "f929b261-4b0f-492f-bed9-2956720348de", + "isActive": false, + "balance": "$2,982.27", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Underwood", + "last": "Mcintosh" + }, + "company": "DIGIFAD", + "email": "underwood.mcintosh@digifad.name", + "phone": "+1 (866) 561-3235", + "address": "701 Green Street, Sattley, Virgin Islands, 9364", + "about": "Magna amet occaecat cillum consequat do deserunt. Voluptate tempor quis quis dolore anim qui duis. Mollit id adipisicing officia eiusmod irure nulla cillum qui. Ad pariatur esse laboris cillum pariatur sit nulla proident nisi ad. Eu sint pariatur pariatur voluptate quis reprehenderit incididunt et. Ex sint qui magna magna exercitation aliquip proident.", + "registered": "Saturday, November 12, 2016 8:16 PM", + "latitude": "-22.025971", + "longitude": "11.665505", + "tags": [ + "ipsum", + "nisi", + "culpa", + "nostrud", + "fugiat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Blair Sellers" + }, + { + "id": 1, + "name": "Cassandra Hogan" + }, + { + "id": 2, + "name": "Leigh Bates" + } + ], + "greeting": "Hello, Underwood! You have 6 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580b373021ad119b0930", + "index": 5, + "guid": "c1975c9b-fdb7-4f9c-895e-57b72ac47d0d", + "isActive": true, + "balance": "$1,818.80", + "picture": "http://placehold.it/32x32", + "age": 29, + "eyeColor": "blue", + "name": { + "first": "Bridget", + "last": "Duran" + }, + "company": "XUMONK", + "email": "bridget.duran@xumonk.org", + "phone": "+1 (896) 458-3115", + "address": "209 Joval Court, Bannock, California, 6346", + "about": "Aliqua minim excepteur commodo enim culpa ad. Aliqua eu dolor veniam velit occaecat aliqua elit tempor. Incididunt adipisicing ipsum cupidatat tempor commodo qui cupidatat et aute. Commodo elit consectetur Lorem excepteur laborum quis commodo magna esse dolore do eiusmod consectetur. Et ut occaecat eiusmod excepteur minim irure elit do ipsum veniam. Et dolore qui commodo qui est aliquip reprehenderit consectetur. Adipisicing laborum occaecat labore ipsum consectetur.", + "registered": "Tuesday, April 8, 2014 2:40 PM", + "latitude": "-58.522426", + "longitude": "-57.612181", + "tags": [ + "dolor", + "aute", + "anim", + "ea", + "et" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Good Neal" + }, + { + "id": 1, + "name": "Hebert Medina" + }, + { + "id": 2, + "name": "Hubbard Ashley" + } + ], + "greeting": "Hello, Bridget! You have 10 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580b92443d6539174cf1", + "index": 6, + "guid": "7262a62f-8665-4d8d-a940-25e9ccab8dbe", + "isActive": true, + "balance": "$3,555.71", + "picture": "http://placehold.it/32x32", + "age": 39, + "eyeColor": "brown", + "name": { + "first": "Corinne", + "last": "Morin" + }, + "company": "BLEEKO", + "email": "corinne.morin@bleeko.info", + "phone": "+1 (944) 490-2121", + "address": "358 Stockholm Street, Kanauga, Massachusetts, 8772", + "about": "Officia magna elit occaecat non nostrud. Enim ipsum nostrud culpa ullamco officia excepteur Lorem est deserunt. Incididunt labore irure adipisicing nostrud aliqua do tempor occaecat voluptate magna et non. Deserunt minim dolor veniam elit qui anim nisi excepteur ut velit adipisicing ullamco tempor.", + "registered": "Tuesday, December 19, 2017 1:05 PM", + "latitude": "-34.833629", + "longitude": "-16.77381", + "tags": [ + "aliquip", + "aliquip", + "eu", + "aute", + "in" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Stein Vang" + }, + { + "id": 1, + "name": "Janette Mcintyre" + }, + { + "id": 2, + "name": "Gena Sullivan" + } + ], + "greeting": "Hello, Corinne! You have 10 unread messages.", + "favoriteFruit": "banana" + }, + { + "_id": "5a4a580b49c79d3d1ea8eedf", + "index": 7, + "guid": "51ea29aa-9980-47da-ac84-7d8d26b4e19c", + "isActive": true, + "balance": "$2,332.99", + "picture": "http://placehold.it/32x32", + "age": 25, + "eyeColor": "brown", + "name": { + "first": "Acosta", + "last": "Hoffman" + }, + "company": "LUNCHPAD", + "email": "acosta.hoffman@lunchpad.biz", + "phone": "+1 (812) 450-2665", + "address": "487 Raleigh Place, Alamo, Maine, 6979", + "about": "Ut sint minim irure dolor duis in sit esse consectetur officia minim. Proident duis consectetur culpa occaecat. Do elit aliqua eiusmod minim.", + "registered": "Sunday, October 15, 2017 7:31 PM", + "latitude": "55.181807", + "longitude": "41.036547", + "tags": [ + "ipsum", + "exercitation", + "eiusmod", + "quis", + "mollit" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Margie Lucas" + }, + { + "id": 1, + "name": "Pearlie Mcmahon" + }, + { + "id": 2, + "name": "Kaye Mcdowell" + } + ], + "greeting": "Hello, Acosta! You have 9 unread messages.", + "favoriteFruit": "banana" + } +] + diff --git a/tests/data/json/test0.input b/tests/data/json/test0.input new file mode 100644 index 0000000..1173371 --- /dev/null +++ b/tests/data/json/test0.input @@ -0,0 +1,459 @@ +[ + { + "_id": "5a4a580a0c912af0f37e0c90", + "index": 0, + "guid": "0962bf7e-3740-4e89-9b46-70ae0be4f191", + "isActive": true, + "balance": "$3,133.24", + "picture": "http://placehold.it/32x32", + "age": 33, + "eyeColor": "brown", + "name": { + "first": "Tabatha", + "last": "Burch" + }, + "company": "VERBUS", + "email": "tabatha.burch@verbus.biz", + "phone": "+1 (810) 427-2220", + "address": "777 Pineapple Street, Williamson, West Virginia, 5791", + "about": "Lorem veniam sunt excepteur esse ad consectetur id ut labore. Enim nulla nulla occaecat velit laboris voluptate ut ullamco id culpa amet mollit laboris ad. Laboris qui in officia esse proident minim. Eiusmod cupidatat ipsum enim proident Lorem minim magna nulla ipsum ullamco. Aute nisi labore enim ut officia in esse irure. Voluptate nisi culpa aliquip esse.", + "registered": "Friday, March 7, 2014 12:06 AM", + "latitude": "17.214286", + "longitude": "144.533821", + "tags": [ + "proident", + "proident", + "non", + "do", + "occaecat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wendy Leblanc" + }, + { + "id": 1, + "name": "Evangeline Goodwin" + }, + { + "id": 2, + "name": "Contreras Whitney" + } + ], + "greeting": "Hello, Tabatha! You have 9 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580a765a75a04460ab21", + "index": 1, + "guid": "a1abbb4a-42df-4335-931f-d95118e6ff6d", + "isActive": true, + "balance": "$3,772.41", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Heath", + "last": "Puckett" + }, + "company": "SNACKTION", + "email": "heath.puckett@snacktion.us", + "phone": "+1 (881) 521-2112", + "address": "524 Anchorage Place, Joppa, New York, 2672", + "about": "Do ex ullamco exercitation officia non aliqua ad incididunt et tempor. Duis in irure sunt mollit et anim ex incididunt consequat. Irure do ad in ea ad aliqua do veniam est in quis voluptate.", + "registered": "Saturday, June 14, 2014 1:00 PM", + "latitude": "-61.264717", + "longitude": "-148.845539", + "tags": [ + "dolor", + "ullamco", + "Lorem", + "ad", + "quis" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wood Cooke" + }, + { + "id": 1, + "name": "Molly Henderson" + }, + { + "id": 2, + "name": "Madden Flores" + } + ], + "greeting": "Hello, Heath! You have 9 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580aad9f80006cdf10af", + "index": 2, + "guid": "34eb1a42-c9d6-47a0-bef9-1a39d8c9d3e3", + "isActive": false, + "balance": "$3,246.48", + "picture": "http://placehold.it/32x32", + "age": 26, + "eyeColor": "green", + "name": { + "first": "Morin", + "last": "Copeland" + }, + "company": "DATACATOR", + "email": "morin.copeland@datacator.io", + "phone": "+1 (865) 466-3084", + "address": "716 Ross Street, Healy, South Dakota, 4255", + "about": "Ea mollit do voluptate ipsum. Veniam occaecat sint amet veniam non magna ad dolore esse deserunt sint ut officia. Ea exercitation aute do fugiat reprehenderit qui nostrud dolor amet tempor. Est adipisicing cillum ullamco in deserunt proident qui eiusmod eiusmod veniam elit exercitation non nisi.", + "registered": "Monday, September 21, 2015 1:57 PM", + "latitude": "-38.785254", + "longitude": "-154.992394", + "tags": [ + "duis", + "anim", + "occaecat", + "anim", + "laborum" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Kathie Chase" + }, + { + "id": 1, + "name": "Anne Wong" + }, + { + "id": 2, + "name": "Alexander Lee" + } + ], + "greeting": "Hello, Morin! You have 5 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580af71694d16fed521d", + "index": 3, + "guid": "91778e07-79d1-44f1-9499-f3df9b991d9e", + "isActive": false, + "balance": "$2,269.05", + "picture": "http://placehold.it/32x32", + "age": 34, + "eyeColor": "brown", + "name": { + "first": "Dina", + "last": "Hernandez" + }, + "company": "NAMEGEN", + "email": "dina.hernandez@namegen.co.uk", + "phone": "+1 (890) 467-3197", + "address": "417 Knapp Street, Gouglersville, Palau, 3690", + "about": "Excepteur minim tempor et sint irure adipisicing ex do reprehenderit labore. Est aute ea amet consequat laboris veniam ea tempor amet elit enim. Pariatur sunt laboris tempor ea eu in.", + "registered": "Tuesday, April 29, 2014 8:39 PM", + "latitude": "88.93652", + "longitude": "122.04518", + "tags": [ + "eu", + "nulla", + "mollit", + "adipisicing", + "irure" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Brianna Cochran" + }, + { + "id": 1, + "name": "Herman Mendoza" + }, + { + "id": 2, + "name": "Rose Mcclain" + } + ], + "greeting": "Hello, Dina! You have 6 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580ab638604600c06bc7", + "index": 4, + "guid": "f929b261-4b0f-492f-bed9-2956720348de", + "isActive": false, + "balance": "$2,982.27", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Underwood", + "last": "Mcintosh" + }, + "company": "DIGIFAD", + "email": "underwood.mcintosh@digifad.name", + "phone": "+1 (866) 561-3235", + "address": "701 Green Street, Sattley, Virgin Islands, 9364", + "about": "Magna amet occaecat cillum consequat do deserunt. Voluptate tempor quis quis dolore anim qui duis. Mollit id adipisicing officia eiusmod irure nulla cillum qui. Ad pariatur esse laboris cillum pariatur sit nulla proident nisi ad. Eu sint pariatur pariatur voluptate quis reprehenderit incididunt et. Ex sint qui magna magna exercitation aliquip proident.", + "registered": "Saturday, November 12, 2016 8:16 PM", + "latitude": "-22.025971", + "longitude": "11.665505", + "tags": [ + "ipsum", + "nisi", + "culpa", + "nostrud", + "fugiat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Blair Sellers" + }, + { + "id": 1, + "name": "Cassandra Hogan" + }, + { + "id": 2, + "name": "Leigh Bates" + } + ], + "greeting": "Hello, Underwood! You have 6 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580b373021ad119b0930", + "index": 5, + "guid": "c1975c9b-fdb7-4f9c-895e-57b72ac47d0d", + "isActive": true, + "balance": "$1,818.80", + "picture": "http://placehold.it/32x32", + "age": 29, + "eyeColor": "blue", + "name": { + "first": "Bridget", + "last": "Duran" + }, + "company": "XUMONK", + "email": "bridget.duran@xumonk.org", + "phone": "+1 (896) 458-3115", + "address": "209 Joval Court, Bannock, California, 6346", + "about": "Aliqua minim excepteur commodo enim culpa ad. Aliqua eu dolor veniam velit occaecat aliqua elit tempor. Incididunt adipisicing ipsum cupidatat tempor commodo qui cupidatat et aute. Commodo elit consectetur Lorem excepteur laborum quis commodo magna esse dolore do eiusmod consectetur. Et ut occaecat eiusmod excepteur minim irure elit do ipsum veniam. Et dolore qui commodo qui est aliquip reprehenderit consectetur. Adipisicing laborum occaecat labore ipsum consectetur.", + "registered": "Tuesday, April 8, 2014 2:40 PM", + "latitude": "-58.522426", + "longitude": "-57.612181", + "tags": [ + "dolor", + "aute", + "anim", + "ea", + "et" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Good Neal" + }, + { + "id": 1, + "name": "Hebert Medina" + }, + { + "id": 2, + "name": "Hubbard Ashley" + } + ], + "greeting": "Hello, Bridget! You have 10 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580b92443d6539174cf1", + "index": 6, + "guid": "7262a62f-8665-4d8d-a940-25e9ccab8dbe", + "isActive": true, + "balance": "$3,555.71", + "picture": "http://placehold.it/32x32", + "age": 39, + "eyeColor": "brown", + "name": { + "first": "Corinne", + "last": "Morin" + }, + "company": "BLEEKO", + "email": "corinne.morin@bleeko.info", + "phone": "+1 (944) 490-2121", + "address": "358 Stockholm Street, Kanauga, Massachusetts, 8772", + "about": "Officia magna elit occaecat non nostrud. Enim ipsum nostrud culpa ullamco officia excepteur Lorem est deserunt. Incididunt labore irure adipisicing nostrud aliqua do tempor occaecat voluptate magna et non. Deserunt minim dolor veniam elit qui anim nisi excepteur ut velit adipisicing ullamco tempor.", + "registered": "Tuesday, December 19, 2017 1:05 PM", + "latitude": "-34.833629", + "longitude": "-16.77381", + "tags": [ + "aliquip", + "aliquip", + "eu", + "aute", + "in" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Stein Vang" + }, + { + "id": 1, + "name": "Janette Mcintyre" + }, + { + "id": 2, + "name": "Gena Sullivan" + } + ], + "greeting": "Hello, Corinne! You have 10 unread messages.", + "favoriteFruit": "banana" + }, + { + "_id": "5a4a580b49c79d3d1ea8eedf", + "index": 7, + "guid": "51ea29aa-9980-47da-ac84-7d8d26b4e19c", + "isActive": true, + "balance": "$2,332.99", + "picture": "http://placehold.it/32x32", + "age": 25, + "eyeColor": "brown", + "name": { + "first": "Acosta", + "last": "Hoffman" + }, + "company": "LUNCHPAD", + "email": "acosta.hoffman@lunchpad.biz", + "phone": "+1 (812) 450-2665", + "address": "487 Raleigh Place, Alamo, Maine, 6979", + "about": "Ut sint minim irure dolor duis in sit esse consectetur officia minim. Proident duis consectetur culpa occaecat. Do elit aliqua eiusmod minim.", + "registered": "Sunday, October 15, 2017 7:31 PM", + "latitude": "55.181807", + "longitude": "41.036547", + "tags": [ + "ipsum", + "exercitation", + "eiusmod", + "quis", + "mollit" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Margie Lucas" + }, + { + "id": 1, + "name": "Pearlie Mcmahon" + }, + { + "id": 2, + "name": "Kaye Mcdowell" + } + ], + "greeting": "Hello, Acosta! You have 9 unread messages.", + "favoriteFruit": "banana" + } +] + diff --git a/tests/test_filedata.py b/tests/test_filedata.py new file mode 100644 index 0000000..c4ba287 --- /dev/null +++ b/tests/test_filedata.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +import pytest +import json + + +def test_json_data(data_json): + parsed = json.loads(data_json.input) + assert data_json.expected == parsed diff --git a/tests/test_requests.py b/tests/test_requests.py new file mode 100644 index 0000000..3c682d2 --- /dev/null +++ b/tests/test_requests.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +import requests +import pytest + +@pytest.RequestData("req") +def test_request(): + pass diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8793853 --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ + +[tox] +envlist = py27 + +[testenv] +passenv = CI TRAVIS* +commands = py.test --cov-report=term-missing --cov-report=xml --cov={envsitepackagesdir}/pytest_filedata + codecov -e TOXENV +deps = -r{toxinidir}/facsimile/requirements.txt + -r{toxinidir}/facsimile/requirements-test.txt + +[pytest] +norecursedirs = .facsimile data gen .tox +