CINF / PyExpLabSys

Python for Experimental Lab Systems: Serial drivers, file parsers, data and live sockets
GNU General Public License v3.0
74 stars 33 forks source link

Communications collecting pyserial for functional tests #71

Closed KennethNielsen closed 7 months ago

KennethNielsen commented 8 months ago

This PR adds a few classes which makes it possible to collect serial communications traces and write tests around them.

There are examples in the documentation that will hopefully show how to use them.

The logic of the replaying, what consitutes a failure and so on is not perfect, but I found this sufficient for our use.

The one aspect of this implementation that I'm not really happy about is that the communications traces are saved BASE64 encoded in a JSON file. This is annoying, as I would prefer them to be human readable. However, it was more important for me to have them in a structured format, where I can have several reads and writes in one file. Unfortunately the text encoding which would be perfect for this, which is ASCII when it is ASCII and hex codes when it is not, as far as I can tell doesn't exist, so I can't have both, resulting is this slightly annoying compromise.

robertjensen commented 8 months ago

I will have to expose my own lack of knowledge here, and ask for the ... in the flush() function?

KennethNielsen commented 8 months ago

I will have to expose my own lack of knowledge here, and ask for the ... in the flush() function?

Oh. The ellipsis was added to Python some time ago as a synonym for pass.

It was sort of a silly addition, since it was essentially done, as I remember it, to make it a little nicer to look interfaces and the sorts, where you need that everywhere, and to make it even easier to write pseudo code which is actually valid Python. For me it just stuck.

robertjensen commented 8 months ago

Oh... nobody tells me anything. I have to agree this is silly... what happened to: There should be one-- and preferably only one --obvious way to do it. ....

Anyway....

KennethNielsen commented 8 months ago

Oh... nobody tells me anything. I have to agree this is silly... what happened to: There should be one-- and preferably only one --obvious way to do it. ....

Anyway....

It seem to have been slackened over time. We also have 3 ways of formatting strings. But we are still not C++.

KennethNielsen commented 8 months ago

I am not a converted fan of the ... syntax, but otherwise this seems quite excellent 👍

If this is only a small grievance, I will probably keep it as is. So I can keep merging any change I may have locally cleanly into PyExpLabSys.