koodaamo/tnefparse

Raise test coverage to 100%

jugmac00 opened this issue · 6 comments

While test coverage is already at a very good 93%, the PR #84 alone would have brought two regressions (changed log level + no more help text), as there are still some lines without coverage.

I suggest to fill the coverage gaps before continuing to work on the current open PRs.

I tried to come up with a test for...

def systime(byte_arr, offset=0):
ft = uint64(byte_arr, offset)
try:
return datetime.utcfromtimestamp((ft - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS)
except: # noqa: E722
microseconds = ft / 10
return (datetime(1601, 1, 1) + timedelta(microseconds=microseconds))

I even wrote a helper to iterate over date/time ranges, but I found no value which fails for the try block and succeeds for the except block.

The change was introduced in be35566

@Beercow @petri Maybe you know or remember why this try/except statement was introduced in the first place?

Hi @Beercow

thank you very much for getting back to me.

As you seem to have some more domain knowledge in this topic, could you give me a microsecond number which is too large, but fits the condition in the except branch?

        microseconds = ft / 10
        return (datetime(1601, 1, 1) + timedelta(microseconds=microseconds))

As I wrote above, I did not find a number on my own.

Here is the complete code snippet:

def systime(byte_arr, offset=0):
ft = uint64(byte_arr, offset)
try:
return datetime.utcfromtimestamp((ft - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS)
except: # noqa: E722
microseconds = ft / 10
return (datetime(1601, 1, 1) + timedelta(microseconds=microseconds))

petri commented

Maybe this is simply to overcome the fact that the max for python timestamps and dates is different? https://stackoverflow.com/questions/39153700/why-cant-pythons-datetime-max-survive-a-round-trip-through-timestamp-fromtim

Unfortunately, I do not have the file I was working with anymore. Trying to find one that brings up the error.