Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Apr 15, 2017
1 parent 8130693 commit 8fab397
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 313 deletions.
286 changes: 0 additions & 286 deletions atx/cmds/webide.py

This file was deleted.

15 changes: 15 additions & 0 deletions atx/strutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ def decode(s, encodings=['utf-8', 'gbk', 'cp936']):
raise UnicodeDecodeError(','.join(encodings), "", 0, len(s or ''), "string: '%s'" % repr(s))


def to_string(s, encoding='utf-8'):
"""
Accept unicode(py2) or bytes(py3)
Returns:
py2 type: str
py3 type: str
"""
if six.PY2:
return s.encode(encoding)
if isinstance(s, bytes):
return s.decode(encoding)
return s


if __name__ == '__main__':
print('Hello 世界!')
print(encode('Hello 世界!'))
Expand Down
1 change: 1 addition & 0 deletions tests/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ cd $(dirname $0)
python -mpytest -v \
test_ext_report.py \
test_dummy.py \
test_strutils.py \
test_base.py "$@"
11 changes: 0 additions & 11 deletions tests/test_jsonlog.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/test_patch.py

This file was deleted.

18 changes: 18 additions & 0 deletions tests/test_strutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from atx import strutils
import six


def test_encode():
v = strutils.encode('hello')
assert not isinstance(v, six.text_type)

v = strutils.encode(u'hello')
assert not isinstance(v, six.text_type)


def test_to_string():
v = strutils.to_string('hello')
assert isinstance(v, str) # no matter py2 or py3

0 comments on commit 8fab397

Please sign in to comment.