From 70fd6193f6c259b7c30a20c7c6122175426416ab Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Mon, 11 Dec 2017 22:50:06 +0330 Subject: [PATCH] Add some tests for `to_bytestring` util --- tests/test_util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 6660f66e..51307423 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -59,3 +59,13 @@ def test_import_app(): util.import_app('support:wrong_app') msg = "Failed to find application object 'wrong_app' in 'support'" assert msg in str(err) + + +def test_to_bytestring(): + assert util.to_bytestring('test_str', 'ascii') == b'test_str' + assert util.to_bytestring('test_strĀ®') == b'test_str\xc2\xae' + assert util.to_bytestring(b'byte_test_str') == b'byte_test_str' + with pytest.raises(TypeError) as err: + util.to_bytestring(100) + msg = '100 is not a string' + assert msg in str(err)