From 887f70f595399c46698ad515ce1e19e4d44d54ac Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Thu, 24 Apr 2014 18:20:23 +0200 Subject: [PATCH] Added CONTRIBUTING.rst. --- CONTRIBUTING.rst | 85 +++++++++++++++++++++++++++++++++++++++++ README.rst | 57 +++++---------------------- requirements-dev.txt | 1 - tests/README.rst | 8 ++++ tests/test_cli.py | 13 +++---- tests/test_docs.py | 37 +++++++++++------- tests/test_downloads.py | 8 +--- tests/test_httpie.py | 1 - tests/test_output.py | 6 +-- tests/test_stream.py | 5 ++- tox.ini | 4 ++ 11 files changed, 140 insertions(+), 85 deletions(-) create mode 100644 CONTRIBUTING.rst create mode 100644 tests/README.rst diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 00000000..bdf5903c --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,85 @@ +Contributing to HTTPie +###################### + +Bug reports and code and documentation patches are greatly appretiated. You can +also help by using the development version of HTTPie and reporting any bugs you +might encounter. + +Bug Reports +=========== + +Along with a description of the problem, please provide the output of the +failing command with the ``--debug`` flag, e.g.: + +.. code-block:: bash + + $ http --debug [minimal set of arguments that trigger the error] + + +Contributing Code and Documentation +=================================== + +Before working on a new feature or a bug, please browse `existing issues`_ +to see whether it has been previously discussed. If the change in question +is a bigger one, it's always good to discuss before your starting working on +it. + + +Development Environment +----------------------- + +.. code-block:: bash + + git clone https://github.com//httpie + + cd httpie + + git checkout -b my_topical_branch + + # (Recommended: create a new virtualenv) + + # Install dev. requirements: + pip install -r requirements-dev.txt + + # Install HTTPie in editable mode + # (the `http' command will point to your working copy): + pip install --upgrade --force-reinstall --editable . + + +Making Changes +-------------- + +Please make sure your changes conform to `Style Guide for Python Code`_ (PEP8). + + +Tests +----- + +Before opening a pull requests, please make sure the `test suite`_ passes +in all of the `supported Python environments`_. You should also **add tests +for any new features and bug fixes**. + +HTTPie uses `pytest`_ and `Tox`_. + +.. code-block:: bash + + # Run all tests on the current Python: + python setup.py test + + # Run all tests on all installed supported Pythons: + tox + + # Run specific tests: + pytest tests/test_uploads.py + + +Don't forget to add yourself to `AUTHORS.rst`_. + + +.. _Tox: http://tox.testrun.org +.. _supported Python environments: https://github.com/jkbr/httpie/blob/master/tox.ini +.. _existing issues: https://github.com/jkbr/httpie/issues?state=open +.. _AUTHORS.rst: https://github.com/jkbr/httpie/blob/master/AUTHORS.rst +.. _pytest: http://pytest.org/ +.. _Style Guide for Python Code: http://python.org/dev/peps/pep-0008/ +.. _test suite: https://github.com/jkbr/httpie/tree/master/tests diff --git a/README.rst b/README.rst index a6d2c81b..91db1e5a 100644 --- a/README.rst +++ b/README.rst @@ -801,9 +801,9 @@ verbatim contents of that XML file with ``Content-Type: application/xml``: $ http PUT httpbin.org/put @/data/file.xml -================= +=============== Terminal Output -================= +=============== HTTPie does several things by default in order to make its terminal output easy to read. @@ -1201,51 +1201,14 @@ HTTPie reaches its final version ``1.0``. All changes are recorded in the Contribute ========== -Bug reports and code and documentation patches are greatly appretiated. You can -also help by using the development version of HTTPie and reporting any bugs you -might encounter. - -Before working on a new feature or a bug, please browse the `existing issues`_ -to see whether it has been previously discussed. If the change in question -is a bigger one, it's always good to discuss before your starting working on -it. - -Then fork and clone `the repository`_. - -It's very useful to point the ``http`` command to your local branch during -development. To do so, install HTTPie with ``pip`` in editable mode: - -.. code-block:: bash - - $ pip install --upgrade --force-reinstall --editable . +Please see `CONTRIBUTING`_. -Please run the existing suite of tests before a pull request is submitted: - -.. code-block:: bash - - python setup.py test - - -`Tox`_ can also be used to conveniently run tests in all of the -`supported Python environments`_: - -.. code-block:: bash - - # Install tox - pip install tox - - # Run tests - tox - - -Don't forget to add yourself to `AUTHORS.rst`_. - -======= +==== Logo -======= +==== -See `claudiatd/httpie-artwork`_ +Please see `claudiatd/httpie-artwork`_ ======= Authors @@ -1270,6 +1233,7 @@ Changelog * `0.9.0-dev`_ * Added ``--cert`` and ``--certkey`` parameters to specify a client side certificate and private key for SSL + * Started using pytest. * `0.8.0`_ (2014-01-25) * Added ``field=@file.txt`` and ``field:=@file.json`` for embedding the contents of text and JSON files into request data. @@ -1376,14 +1340,10 @@ Changelog .. _Requests: http://python-requests.org .. _Pygments: http://pygments.org/ .. _pip: http://www.pip-installer.org/en/latest/index.html -.. _Tox: http://tox.testrun.org .. _Github API: http://developer.github.com/v3/issues/comments/#create-a-comment -.. _supported Python environments: https://github.com/jkbr/httpie/blob/master/tox.ini -.. _the repository: https://github.com/jkbr/httpie .. _these fine people: https://github.com/jkbr/httpie/contributors .. _Jakub Roztocil: http://subtleapps.com .. _@jkbrzt: https://twitter.com/jkbrzt -.. _existing issues: https://github.com/jkbr/httpie/issues?state=open .. _claudiatd/httpie-artwork: https://github.com/claudiatd/httpie-artwork .. _0.1.6: https://github.com/jkbr/httpie/compare/0.1.4...0.1.6 .. _0.2.0: https://github.com/jkbr/httpie/compare/0.1.6...0.2.0 @@ -1401,5 +1361,6 @@ Changelog .. _0.7.1: https://github.com/jkbr/httpie/compare/0.6.0...0.7.1 .. _0.8.0: https://github.com/jkbr/httpie/compare/0.7.1...0.8.0 .. _0.9.0-dev: https://github.com/jkbr/httpie/compare/0.8.0...master -.. _AUTHORS.rst: https://github.com/jkbr/httpie/blob/master/AUTHORS.rst .. _LICENSE: https://github.com/jkbr/httpie/blob/master/LICENSE +.. _Tox: http://tox.testrun.org +.. _CONTRIBUTING: https://github.com/jkbr/httpie/blob/master/CONTRIBUTING.rst diff --git a/requirements-dev.txt b/requirements-dev.txt index f5698407..9e5e31fa 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,3 @@ tox pytest -git+git://github.com/kennethreitz/httpbin.git@7c96875e87a448f08fb1981e85eb79e77d592d98 docutils diff --git a/tests/README.rst b/tests/README.rst new file mode 100644 index 00000000..15feb581 --- /dev/null +++ b/tests/README.rst @@ -0,0 +1,8 @@ +HTTPie Test Suite +================= + + +Please see `CONTRIBUTING`_. + + +.. _CONTRIBUTING: https://github.com/jkbr/httpie/blob/master/CONTRIBUTING.rst diff --git a/tests/test_cli.py b/tests/test_cli.py index ebb26f6b..f9e057ee 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -5,23 +5,20 @@ from unittest import TestCase # noinspection PyCompatibility import argparse +from httpie import input +from httpie.input import KeyValue, KeyValueArgType +from httpie import ExitStatus +from httpie.cli import parser from tests import TestEnvironment, http, httpbin, HTTP_OK from tests.fixtures import ( FILE_PATH_ARG, JSON_FILE_PATH_ARG, JSON_FILE_CONTENT, FILE_CONTENT, FILE_PATH ) -from httpie import input -from httpie.input import KeyValue, KeyValueArgType -from httpie import ExitStatus -from httpie.cli import parser - class ItemParsingTest(TestCase): def setUp(self): - self.key_value_type = KeyValueArgType( - *input.SEP_GROUP_ALL_ITEMS - ) + self.key_value_type = KeyValueArgType(*input.SEP_GROUP_ALL_ITEMS) def test_invalid_items(self): items = ['no-separator'] diff --git a/tests/test_docs.py b/tests/test_docs.py index 780598ad..acee19bc 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,4 +1,5 @@ import os +import fnmatch import subprocess from unittest import TestCase @@ -11,26 +12,34 @@ def has_docutils(): try: #noinspection PyUnresolvedReferences import docutils + return True except ImportError: return False -def get_readme_errors(): - p = subprocess.Popen([ - 'rst2pseudoxml.py', - '--report=1', - '--exit-status=1', - os.path.join(TESTS_ROOT, '..', 'README.rst') - ], stderr=subprocess.PIPE, stdout=subprocess.PIPE) +def validate_rst(filename): + p = subprocess.Popen( + ['rst2pseudoxml.py', '--report=1', '--exit-status=1', filename], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE + ) err = p.communicate()[1] - if p.returncode: - return err + assert p.returncode == 0, err -class READMETest(TestCase): +def rst_files(): + for root, dirnames, filenames in os.walk(os.path.dirname(TESTS_ROOT)): + if '.tox' not in root: + for filename in fnmatch.filter(filenames, '*.rst'): + yield os.path.join(root, filename) - @pytest.mark.skipif(not has_docutils(), reason='docutils not installed') - def test_README_reStructuredText_valid(self): - errors = get_readme_errors() - assert not errors, errors + +@pytest.mark.skipif(not has_docutils(), reason='docutils not installed') +class RSTTest(TestCase): + + def test_rst_files_syntax(self): + paths = list(rst_files()) + assert paths, 'no .rst files found, which is weird' + for path in paths: + validate_rst(path) diff --git a/tests/test_downloads.py b/tests/test_downloads.py index 7661cdc1..37b25778 100644 --- a/tests/test_downloads.py +++ b/tests/test_downloads.py @@ -7,12 +7,8 @@ from requests.structures import CaseInsensitiveDict from httpie.compat import urlopen from httpie.downloads import ( - parse_content_range, - filename_from_content_disposition, - filename_from_url, - get_unique_filename, - ContentRangeError, - Download, + parse_content_range, filename_from_content_disposition, filename_from_url, + get_unique_filename, ContentRangeError, Download, ) from tests import httpbin, http, TestEnvironment diff --git a/tests/test_httpie.py b/tests/test_httpie.py index c6e34e30..b4a9e142 100644 --- a/tests/test_httpie.py +++ b/tests/test_httpie.py @@ -36,7 +36,6 @@ class HTTPieTest(TestCase): assert r.json['form'] == {'foo': ['bar', 'baz']} def test_POST_stdin(self): - with open(FILE_PATH) as f: env = TestEnvironment(stdin=f, stdin_isatty=False) r = http('--form', 'POST', httpbin('/post'), env=env) diff --git a/tests/test_output.py b/tests/test_output.py index b5ebd6e8..3d1d6c31 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -1,11 +1,7 @@ from unittest import TestCase from httpie import ExitStatus -from tests import ( - TestEnvironment, - http, httpbin, - HTTP_OK, COLOR, CRLF -) +from tests import TestEnvironment, http, httpbin, HTTP_OK, COLOR, CRLF class VerboseFlagTest(TestCase): diff --git a/tests/test_stream.py b/tests/test_stream.py index 87c83778..c2eafc3a 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -40,8 +40,9 @@ class StreamTest(TestCase): """Test that --stream works with non-prettified redirected terminal output.""" with open(BIN_FILE_PATH, 'rb') as f: - env = TestEnvironment(stdout_isatty=False, stdin=f, - stdin_isatty=False) + env = TestEnvironment(stdout_isatty=False, + stdin_isatty=False, + stdin=f) r = http('--pretty=none', '--stream', '--verbose', 'GET', httpbin('/get'), env=env) # We get 'Bad Request' but it's okay. diff --git a/tox.ini b/tox.ini index 7ce95a13..eb160fc1 100644 --- a/tox.ini +++ b/tox.ini @@ -11,3 +11,7 @@ commands = {envpython} setup.py test [testenv:py26] deps = argparse + +[testenv:py27] +# Install docutils to test .rst files syntax +deps = docutils