sylikc / pyexiftool

PyExifTool (active PyPI project) - A Python library to communicate with an instance of Phil Harvey's ExifTool command-line application. Runs one process with special -stay_open flag, and pipes data to/from. Much more efficient than running a subprocess for each command!
Other
148 stars 19 forks source link

Test basic functionality #20

Closed jangop closed 2 years ago

jangop commented 3 years ago

A lot of basic functionality is brittle at the moment. All four implemented tests currently fail.

sylikc commented 3 years ago

@jangop thanks very much for reviewing and testing the v0.5.x branch

Funny thing, I actually had just fixed https://github.com/sylikc/pyexiftool/commit/1089e24ec737744cc511f056669f14abf9fed5fb the ExifToolHelper() breaking when merging your set_tags() PR into this branch. I'll probably fix it in a more robust way in the main ExifTool class later.

I still haven't quite figured out what to do with the -w flag. It really messes up the -j output.

Keep them tests coming! I'm slowly working on the ExifToolHelper class. All the stuff I had merged in before really needs to get revamped. I'll look into the get_metadata lol... I must've dreamt I made that function really robust 😞

sylikc commented 3 years ago

Oh, and yeah the ExifToolHelper currently isn't as robust as the ExifTool class itself. And, I'm pretty new to writing tests.

But I reviewed these failures now, and they do need to be fixed, but how is a good question. For test_read_all_from_no_file and test_read_all_from_nonexistent_file it all boils down to https://github.com/sylikc/pyexiftool/blob/v0.5.x-py3-refactor/exiftool/exiftool.py#L798 and not having decided what an empty JSON should return.

There are legitimate reasons why execute_json will return an empty result. And they're not an error. For example, writing tags returns no output.

I guess it's "possible" to use ExifTool.last_stderr to analyze it from the ExifToolHelper call... maybe.

See this test code:

print( "json =", et.execute_json("rose.jpg", "-JFIF:JFIFVersion") )
print("stderr =", et.last_stderr)

print( "json =", et.execute_json(*["rose.jpg", "-MakerNotes="]) )
print("stderr =", et.last_stderr)

output:

json = [{'SourceFile': 'rose.jpg', 'JFIF:JFIFVersion': '1 1'}]
stderr = b''
json = None
stderr = b'0 image files updated\r\n    1 image files unchanged\r\n'

I guess get_metadata/get_tags should raise an error on a None return from execute_json?

sylikc commented 3 years ago

I'm going to ask on the exiftool forums to see if there's a way to get more error related information from stderr Exiftool force output of "image files read" . That would really solve the problem, or at least allow the helper to do more error checking

sylikc commented 3 years ago

I just pushed a few commits that read out the status code from the last executed command sequence... hopefully that will help the helper determine pass/fail later.

Only problem is, it returns 0 if everything is good, but 1 if one or more failures occurred. It's not a very precise status...

The helper could help parse stderr, but that kinda is going to be messy given that the output from exiftool is more for humans to read

jangop commented 3 years ago

I am all for making this wrapper around `ExifTool robust and convenient, so I really appreciate your effort.