da4089 / simplefix

Simple FIX protocol implementation for Python
MIT License
229 stars 63 forks source link

Test fails: 'FixMessage' object has no attribute 'to_string' #46

Closed ekkis closed 1 year ago

ekkis commented 1 year ago

I grabbed simplefix/test/test_message.py and tried to run it but it fails the following test:

$ python3.9 t

........................................./usr/local/lib/python3.9/site-packages/simplefix/message.py:147: DeprecationWarning: simplefix.FixMessage.append_time() is deprecated. Use append_utc_timestamp() or append_tz_timestamp() instead. warnings.warn("simplefix.FixMessage.append_time() is deprecated. " ........E...........................................

ERROR: test_to_String (main.MessageTests) Test conversion to string with separator.

Traceback (most recent call last): File "/Users/ekkis/dev/t", line 875, in test_to_String buffer = msg.to_string('XXX') AttributeError: 'FixMessage' object has no attribute 'to_string'


Ran 93 tests in 0.018s

FAILED (errors=1)

what does it need?

da4089 commented 1 year ago

Huh. That's kinda curious ...

My results:

(venv310) d@Davids-Laptop > env PYTHONPATH=. python test/test_message.py 
........................................./Users/d/w/simplefix-2/simplefix/message.py:147: DeprecationWarning: simplefix.FixMessage.append_time() is deprecated. Use append_utc_timestamp() or append_tz_timestamp() instead.
  warnings.warn("simplefix.FixMessage.append_time() is deprecated. "
....................................................
----------------------------------------------------------------------
Ran 93 tests in 0.005s

OK
(venv310) d@Davids-Laptop > 

The deprecation warnings are expected, and fine, but it looks like your FixMessage doesn't have the to_string() method, which is pretty odd.

I have no idea how this could be happening. If possible, could you check a couple of things?

>>> import simplefix
>>> print(simplefix.__file__)
/Users/d/w/simplefix-2/simplefix/__init__.py
>>> ```

Thanks for the report, I'm very keen to figure this one out!

ekkis commented 1 year ago

I see: /usr/local/lib/python3.9/site-packages/simplefix/__init__.py. in the message.py I see:

582     def __str__(self):
583         """Return string form of message contents."""
584         s = ""
585         for tag, value in self.pairs:
586             if s:
587                 s += "|"
588             s += tag.decode("ascii") + "=" + value.decode("ascii")
589         return s
da4089 commented 1 year ago

Thank you for that. I think I understand what's going on now.

The test_message.py file that you've copied is from the master branch, but I think you're running it against the v1.0.15 installed package. The to_string method was added after v1.0.15 was released.

See this commit https://github.com/da4089/simplefix/commit/1de83d2d61a265364b54bf35f446ec352995682b

You could download the v1.0.15 version of test_message.py from https://github.com/da4089/simplefix/blob/v1.0.15/test/test_message.py, and it should run with just the deprecation warnings.

ekkis commented 1 year ago

that makes perfect sense. I installed using pip so I got whatever version is available from the repo but to test I cloned. thank you very much