mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 08:22:22 +02:00
Finished pytest migration.
This commit is contained in:
parent
3cb124bba7
commit
3d079942f4
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ dist
|
|||||||
httpie.egg-info
|
httpie.egg-info
|
||||||
build
|
build
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*.egg
|
||||||
.tox
|
.tox
|
||||||
README.html
|
README.html
|
||||||
.coverage
|
.coverage
|
||||||
|
@ -10,20 +10,20 @@ def humanize_bytes(n, precision=2):
|
|||||||
Assumes `from __future__ import division`.
|
Assumes `from __future__ import division`.
|
||||||
|
|
||||||
>>> humanize_bytes(1)
|
>>> humanize_bytes(1)
|
||||||
'1 byte'
|
'1 B'
|
||||||
>>> humanize_bytes(1024)
|
>>> humanize_bytes(1024, precision=1)
|
||||||
'1.0 kB'
|
'1.0 kB'
|
||||||
>>> humanize_bytes(1024 * 123)
|
>>> humanize_bytes(1024 * 123, precision=1)
|
||||||
'123.0 kB'
|
'123.0 kB'
|
||||||
>>> humanize_bytes(1024 * 12342)
|
>>> humanize_bytes(1024 * 12342, precision=1)
|
||||||
'12.1 MB'
|
'12.1 MB'
|
||||||
>>> humanize_bytes(1024 * 12342, 2)
|
>>> humanize_bytes(1024 * 12342, precision=2)
|
||||||
'12.05 MB'
|
'12.05 MB'
|
||||||
>>> humanize_bytes(1024 * 1234, 2)
|
>>> humanize_bytes(1024 * 1234, precision=2)
|
||||||
'1.21 MB'
|
'1.21 MB'
|
||||||
>>> humanize_bytes(1024 * 1234 * 1111, 2)
|
>>> humanize_bytes(1024 * 1234 * 1111, precision=2)
|
||||||
'1.31 GB'
|
'1.31 GB'
|
||||||
>>> humanize_bytes(1024 * 1234 * 1111, 1)
|
>>> humanize_bytes(1024 * 1234 * 1111, precision=1)
|
||||||
'1.3 GB'
|
'1.3 GB'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
tox
|
tox
|
||||||
|
pytest
|
||||||
git+git://github.com/kennethreitz/httpbin.git@7c96875e87a448f08fb1981e85eb79e77d592d98
|
git+git://github.com/kennethreitz/httpbin.git@7c96875e87a448f08fb1981e85eb79e77d592d98
|
||||||
docutils
|
docutils
|
||||||
|
36
setup.py
36
setup.py
@ -1,16 +1,32 @@
|
|||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
from setuptools.command.test import test as TestCommand
|
||||||
|
|
||||||
import httpie
|
import httpie
|
||||||
|
|
||||||
|
|
||||||
if sys.argv[-1] == 'test':
|
class PyTest(TestCommand):
|
||||||
status = os.system('python tests/tests.py')
|
def finalize_options(self):
|
||||||
sys.exit(1 if status > 127 else status)
|
TestCommand.finalize_options(self)
|
||||||
|
self.test_suite = True
|
||||||
|
self.test_args = [
|
||||||
|
'--doctest-modules',
|
||||||
|
'./httpie', './tests'
|
||||||
|
]
|
||||||
|
self.test_suite = True
|
||||||
|
|
||||||
|
def run_tests(self):
|
||||||
|
import pytest
|
||||||
|
sys.exit(pytest.main(self.test_args))
|
||||||
|
|
||||||
|
|
||||||
requirements = [
|
tests_require = [
|
||||||
|
'pytest',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
install_requires = [
|
||||||
'requests>=2.0.0',
|
'requests>=2.0.0',
|
||||||
'Pygments>=1.5'
|
'Pygments>=1.5'
|
||||||
]
|
]
|
||||||
@ -18,11 +34,11 @@ try:
|
|||||||
#noinspection PyUnresolvedReferences
|
#noinspection PyUnresolvedReferences
|
||||||
import argparse
|
import argparse
|
||||||
except ImportError:
|
except ImportError:
|
||||||
requirements.append('argparse>=1.2.1')
|
install_requires.append('argparse>=1.2.1')
|
||||||
|
|
||||||
if 'win32' in str(sys.platform).lower():
|
if 'win32' in str(sys.platform).lower():
|
||||||
# Terminal colors for Windows
|
# Terminal colors for Windows
|
||||||
requirements.append('colorama>=0.2.4')
|
install_requires.append('colorama>=0.2.4')
|
||||||
|
|
||||||
|
|
||||||
def long_description():
|
def long_description():
|
||||||
@ -46,7 +62,11 @@ setup(
|
|||||||
'http = httpie.__main__:main',
|
'http = httpie.__main__:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
install_requires=requirements,
|
install_requires=install_requires,
|
||||||
|
cmdclass={'test': PyTest},
|
||||||
|
tests_require=tests_require,
|
||||||
|
extras_require={'tests': tests_require},
|
||||||
|
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
|
@ -5,15 +5,13 @@ import json
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
# HACK: Prepend ../ to PYTHONPATH so that we can import httpie form there.
|
|
||||||
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
sys.path.insert(0, os.path.realpath(os.path.join(TESTS_ROOT, '..')))
|
|
||||||
from httpie import ExitStatus
|
from httpie import ExitStatus
|
||||||
from httpie.models import Environment
|
from httpie.models import Environment
|
||||||
from httpie.core import main
|
from httpie.core import main
|
||||||
from httpie.compat import bytes, str
|
from httpie.compat import bytes, str
|
||||||
|
|
||||||
|
|
||||||
|
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||||
HTTPBIN_URL = os.environ.get('HTTPBIN_URL',
|
HTTPBIN_URL = os.environ.get('HTTPBIN_URL',
|
||||||
'http://httpbin.org').rstrip('/')
|
'http://httpbin.org').rstrip('/')
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import pytest
|
||||||
from requests.structures import CaseInsensitiveDict
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
from httpie.compat import urlopen
|
from httpie.compat import urlopen
|
||||||
@ -32,22 +33,22 @@ class DownloadUtilsTest(TestCase):
|
|||||||
assert parse('bytes 100-199/*', 100) == 200
|
assert parse('bytes 100-199/*', 100) == 200
|
||||||
|
|
||||||
# missing
|
# missing
|
||||||
self.assertRaises(ContentRangeError, parse, None, 100)
|
pytest.raises(ContentRangeError, parse, None, 100)
|
||||||
|
|
||||||
# syntax error
|
# syntax error
|
||||||
self.assertRaises(ContentRangeError, parse, 'beers 100-199/*', 100)
|
pytest.raises(ContentRangeError, parse, 'beers 100-199/*', 100)
|
||||||
|
|
||||||
# unexpected range
|
# unexpected range
|
||||||
self.assertRaises(ContentRangeError, parse, 'bytes 100-199/*', 99)
|
pytest.raises(ContentRangeError, parse, 'bytes 100-199/*', 99)
|
||||||
|
|
||||||
# invalid instance-length
|
# invalid instance-length
|
||||||
self.assertRaises(ContentRangeError, parse, 'bytes 100-199/199', 100)
|
pytest.raises(ContentRangeError, parse, 'bytes 100-199/199', 100)
|
||||||
|
|
||||||
# invalid byte-range-resp-spec
|
# invalid byte-range-resp-spec
|
||||||
self.assertRaises(ContentRangeError, parse, 'bytes 100-99/199', 100)
|
pytest.raises(ContentRangeError, parse, 'bytes 100-99/199', 100)
|
||||||
|
|
||||||
# invalid byte-range-resp-spec
|
# invalid byte-range-resp-spec
|
||||||
self.assertRaises(ContentRangeError, parse, 'bytes 100-100/*', 100)
|
pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100)
|
||||||
|
|
||||||
def test_Content_Disposition_parsing(self):
|
def test_Content_Disposition_parsing(self):
|
||||||
parse = filename_from_content_disposition
|
parse = filename_from_content_disposition
|
||||||
|
@ -17,9 +17,10 @@ class VerboseFlagTest(TestCase):
|
|||||||
def test_verbose_form(self):
|
def test_verbose_form(self):
|
||||||
# https://github.com/jkbr/httpie/issues/53
|
# https://github.com/jkbr/httpie/issues/53
|
||||||
r = http('--verbose', '--form', 'POST', httpbin('/post'),
|
r = http('--verbose', '--form', 'POST', httpbin('/post'),
|
||||||
'foo=bar', 'baz=bar')
|
'A=B', 'C=D')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert 'foo=bar&baz=bar' in r
|
# Python 2.6 has no ordered dict, so we test for both orders here.
|
||||||
|
assert 'A=B&C=D' in r or 'C=D&A=B', r
|
||||||
|
|
||||||
def test_verbose_json(self):
|
def test_verbose_json(self):
|
||||||
r = http('--verbose', 'POST', httpbin('/post'), 'foo=bar', 'baz=bar')
|
r = http('--verbose', 'POST', httpbin('/post'), 'foo=bar', 'baz=bar')
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from httpie.input import ParseError
|
from httpie.input import ParseError
|
||||||
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
||||||
from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
||||||
@ -8,7 +10,7 @@ from tests.fixtures import FILE_PATH_ARG, FILE_PATH, FILE_CONTENT
|
|||||||
|
|
||||||
class MultipartFormDataFileUploadTest(TestCase):
|
class MultipartFormDataFileUploadTest(TestCase):
|
||||||
def test_non_existent_file_raises_parse_error(self):
|
def test_non_existent_file_raises_parse_error(self):
|
||||||
with self.assertRaises(ParseError):
|
with pytest.raises(ParseError):
|
||||||
http('--form', 'POST', httpbin('/post'), 'foo@/__does_not_exist__')
|
http('--form', 'POST', httpbin('/post'), 'foo@/__does_not_exist__')
|
||||||
|
|
||||||
def test_upload_ok(self):
|
def test_upload_ok(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user