Repository: falconry/falcon
Pull request #1041 (2017-05-04 05:35:27)

__repr__ implemented
__repr__ implemented for Request, Response, HttpError

https://github.com/falconry/falcon/issues/1025

codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=h1) Report
> Merging [#1041](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=desc) into [master](https://codecov.io/gh/falconry/falcon/commit/27a14e5458b092d44749d621e9c43abbdbb9d245?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1041/graphs/tree.svg?height=150&width=650&token=zOtkfNQ3h6&src=pr)](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master   #1041   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          31      31           
  Lines        2107    2113    +6     
  Branches      338     338           
======================================
+ Hits         2107    2113    +6
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/http\_error.py](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=tree#diff-ZmFsY29uL2h0dHBfZXJyb3IucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [falcon/request.py](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=tree#diff-ZmFsY29uL3JlcXVlc3QucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [falcon/response.py](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=tree#diff-ZmFsY29uL3Jlc3BvbnNlLnB5) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=footer). Last update [27a14e5...06e21ef](https://codecov.io/gh/falconry/falcon/pull/1041?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/falcon/http_error.py b/falcon/http_error.py
index 036d4d0..edeba18 100644
--- a/falcon/http_error.py
+++ b/falcon/http_error.py
@@ -129,6 +129,9 @@ class HTTPError(Exception):
         else:
             self.link = None
 
+    def __repr__(self):
+        return '<%s: %s>' % (self.__class__.__name__, self.status)
+
     @property
     def has_representation(self):
         return True
diff --git a/falcon/request.py b/falcon/request.py
index 6f035a2..c5d4be4 100644
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -421,6 +421,9 @@ class Request(object):
         else:
             self.context = self.context_type()
 
+    def __repr__(self):
+        return '<%s: %s %r>' % (self.__class__.__name__, self.method, self.url)
+
     # ------------------------------------------------------------------------
     # Properties
     # ------------------------------------------------------------------------
diff --git a/falcon/response.py b/falcon/response.py
index b5dfff4..ce06dee 100644
--- a/falcon/response.py
+++ b/falcon/response.py
@@ -153,6 +153,9 @@ class Response(object):
         else:
             self.context = self.context_type()
 
+    def __repr__(self):
+        return '<%s: %s>' % (self.__class__.__name__, self.status)
+
     def set_stream(self, stream, stream_len):
         """Convenience method for setting both `stream` and `stream_len`.
 


Test patch:
diff --git a/tests/test_error.py b/tests/test_error.py
index 55af9e8..2f7358e 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -382,3 +382,8 @@ class TestError(testtools.TestCase):
             self.assertEqual('Test', e.title, 'Title should be "Test"')
             self.assertEqual('Testdescription', e.description,
                              'Description should be "Testdescription"')
+
+    def test_http_error_repr(self):
+        error = falcon.HTTPBadRequest()
+        _repr = '<%s: %s>' % (error.__class__.__name__, error.status)
+        self.assertEqual(error.__repr__(), _repr)
diff --git a/tests/test_request_body.py b/tests/test_request_body.py
index 42f57e4..72c371c 100644
--- a/tests/test_request_body.py
+++ b/tests/test_request_body.py
@@ -72,7 +72,6 @@ class TestRequestBody(testing.TestBase):
         # each time the property is called. Also ensures branch
         # coverage of the property implementation.
         assert bounded_stream is req.bounded_stream
-
         data = bounded_stream.read()
         self.assertEqual(len(data), 0)
 
@@ -142,3 +141,9 @@ class TestRequestBody(testing.TestBase):
         body = request_helpers.Body(stream, expected_len)
         for i, line in enumerate(body):
             self.assertEqual(line, expected_lines[i])
+
+    def test_request_repr(self):
+        environ = testing.create_environ()
+        req = falcon.Request(environ)
+        _repr = '<%s: %s %r>' % (req.__class__.__name__, req.method, req.url)
+        self.assertEquals(req.__repr__(), _repr)
diff --git a/tests/test_response_body.py b/tests/test_response_body.py
index 3ffba4a..33a8bf6 100644
--- a/tests/test_response_body.py
+++ b/tests/test_response_body.py
@@ -15,3 +15,8 @@ class TestResponseBody(testing.TestBase):
             resp.body += ' '
 
         self.assertEqual(resp.body, text)
+
+    def test_response_repr(self):
+        resp = falcon.Response()
+        _repr = '<%s: %s>' % (resp.__class__.__name__, resp.status)
+        self.assertEqual(resp.__repr__(), _repr)