koodaamo / tnefparse

a TNEF decoding library written in python, without external dependencies
GNU Lesser General Public License v3.0
49 stars 37 forks source link

TNEF.__str__ is broken #94

Closed petri closed 3 years ago

petri commented 3 years ago
Traceback (most recent call last):
  File "/Users/petri/Code/koodaamo/tnefparse/tests/utest.py", line 5, in <module>
    print(TNEF(tf.read()))
  File "/Users/petri/Code/koodaamo/tnefparse/tnefparse/tnef.py", line 340, in __str__
    return f"<{self.__class__.__name__}:0x{self.key:2.2x}{atts}>"
ValueError: Precision not allowed in integer format specifier
jugmac00 commented 3 years ago

I have no access to a PC right now, but I will have a look this evening.

I wonder whether this regression was introduced by my "f-strings" commit, which was autogenerated by pyupgrade or whether this was broken before. Either way. I should have tested the change at least manually.

Anyway, afair __str__ has no coverage. Yet another good reason to aim for 100% (#92 ).

jugmac00 commented 3 years ago

Note The str representation was broken for Python 3 from the beginning.

I checked out an older commit where Python 2.7 was still supported, so I had a chance to see what's a correct str representation should look like:

tnefparse on  HEAD (ae186c2) via 🐍 v2.7.17 (venv) 
❯ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tnefparse import TNEF
>>> t = TNEF(open("tests/examples/one-file.tnef", mode="rb").read())
>>> t
<tnefparse.tnef.TNEF object at 0x7f4a67ba9150>
>>> str(t)
'<TNEF:0x237, 1 attachments>'