Skip to content

Commit

Permalink
py2: Update asString to convert derived types to bytes (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Sep 7, 2021
1 parent 798c602 commit 0776735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/fileseq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def asString(obj):
return obj
# derived type check
elif isinstance(obj, bytes):
if not futils.PY2:
if futils.PY2:
obj = bytes(obj)
else:
obj = obj.decode(FILESYSTEM_ENCODING)
else:
obj = futils.text_type(obj)
Expand Down
11 changes: 11 additions & 0 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def testXrange(self):
self.assertEqual(len(expected), len(actual))
self.assertEqual(expected, list(actual))

def testAsString(self):
expect = "my string"
custom = _CustomPathString(expect)
self.assertEqual(expect, custom)

# https://github.com/justinfx/fileseq/issues/106
actual = utils.asString(custom)
self.assertEqual(expect, actual)
self.assertIsInstance(actual, str)
self.assertNotIsInstance(actual, _CustomPathString)


class TestFrameSet(unittest.TestCase):

Expand Down

0 comments on commit 0776735

Please sign in to comment.