From 07767359bc957dc4ba801b9ced3188900d4fe08f Mon Sep 17 00:00:00 2001 From: Justin Israel Date: Wed, 8 Sep 2021 07:28:03 +1200 Subject: [PATCH] py2: Update asString to convert derived types to bytes (#106) --- src/fileseq/utils.py | 4 +++- test/test_unit.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fileseq/utils.py b/src/fileseq/utils.py index a8b034b..4a21f45 100644 --- a/src/fileseq/utils.py +++ b/src/fileseq/utils.py @@ -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) diff --git a/test/test_unit.py b/test/test_unit.py index c64f2da..ceb6270 100755 --- a/test/test_unit.py +++ b/test/test_unit.py @@ -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):