Skip to content

Commit 7c915fb

Browse files
committed
Add test case for dir() support and fix Python 2 support
1 parent 12202ba commit 7c915fb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

suitcase/structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def __setattr__(self, key, value):
294294
return object.__setattr__(self, key, value)
295295

296296
def __dir__(self):
297-
return object.__dir__(self) + [str(k) for k, v in self._sorted_fields]
297+
return dir(type(self)) + [str(k) for k, v in self._sorted_fields]
298298

299299
def __iter__(self):
300300
return iter(self._sorted_fields)

suitcase/test/test_fields.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,5 +1189,14 @@ def test_unpack_greedy_after(self):
11891189
self.assertEqual(m.last.value, b"Doe")
11901190
self.assertEqual(m.greedy, b"Hello World!")
11911191

1192+
1193+
class TestDiscoverableFields(unittest.TestCase):
1194+
def test_dir(self):
1195+
m = PascalString16()
1196+
attrs = dir(m)
1197+
self.assertTrue("length" in attrs)
1198+
self.assertTrue("value" in attrs)
1199+
1200+
11921201
if __name__ == "__main__":
11931202
unittest.main()

0 commit comments

Comments
 (0)