-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add __str__ and __repr__ to Sanic and Bluepring (#2043)
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
|
||
from sanic import Blueprint, Sanic | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
return Sanic("my_app") | ||
|
||
|
||
@pytest.fixture | ||
def bp(app): | ||
return Blueprint("my_bp") | ||
|
||
|
||
def test_app_str(app): | ||
assert str(app) == "<Sanic my_app>" | ||
|
||
|
||
def test_app_repr(app): | ||
assert repr(app) == 'Sanic(name="my_app")' | ||
|
||
|
||
def test_bp_str(bp): | ||
assert str(bp) == "<Blueprint my_bp>" | ||
|
||
|
||
def test_bp_repr(bp): | ||
assert repr(bp) == ( | ||
'Blueprint(name="my_bp", url_prefix=None, host=None, ' | ||
"version=None, strict_slashes=None)" | ||
) | ||
|
||
|
||
def test_bp_repr_with_values(bp): | ||
bp.host = "example.com" | ||
bp.url_prefix = "/foo" | ||
bp.version = 3 | ||
bp.strict_slashes = True | ||
assert repr(bp) == ( | ||
'Blueprint(name="my_bp", url_prefix="/foo", host="example.com", ' | ||
"version=3, strict_slashes=True)" | ||
) |