Repository: stefmolin/exif-stripper

Issue:
Include changed filenames in the output on failure

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`033794f`)](https://app.codecov.io/gh/stefmolin/exif-stripper/commit/033794fc76317d3b9edc2fef18cbf11e97481ac8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin) to head [(`2179c53`)](https://app.codecov.io/gh/stefmolin/exif-stripper/commit/2179c5366be331480e72808150310e218b331f95?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin).

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23/graphs/tree.svg?width=650&height=150&src=pr&token=CZ2Cq1MD3C&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin)](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin)

```diff
@@            Coverage Diff            @@
##              main       #23   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          102       105    +3     
=========================================
+ Hits           102       105    +3     
```

| [Files](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin) | Coverage Δ | |
|---|---|---|
| [src/exif\_stripper/cli.py](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23?src=pr&el=tree&filepath=src%2Fexif_stripper%2Fcli.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin#diff-c3JjL2V4aWZfc3RyaXBwZXIvY2xpLnB5) | `100.00% <100.00%> (ø)` | |
| [tests/test\_cli.py](https://app.codecov.io/gh/stefmolin/exif-stripper/pull/23?src=pr&el=tree&filepath=tests%2Ftest_cli.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `100.00% <100.00%> (ø)` | |

</details>

Patch:
diff --git a/src/exif_stripper/cli.py b/src/exif_stripper/cli.py
index b2cc282..7650ffe 100644
--- a/src/exif_stripper/cli.py
+++ b/src/exif_stripper/cli.py
@@ -32,8 +32,7 @@ def process_image(filename: str | os.PathLike) -> bool:
     try:
         # remove EXIF data
         with Image.open(filename) as im:
-            exif = im.getexif()
-            if exif:
+            if exif := im.getexif():
                 exif.clear()
                 im.save(filename)
                 has_changed = True
@@ -45,11 +44,13 @@ def process_image(filename: str | os.PathLike) -> bool:
             from xattr import xattr
 
             xattr_obj = xattr(filename)
-            extended_attributes = xattr_obj.list()
-            if extended_attributes:
+            if xattr_obj.list():
                 xattr_obj.clear()
                 has_changed = True
 
+    if has_changed:
+        print(f'Stripped metadata from {filename}')
+
     return has_changed
 
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index f33251b..d3b9459 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -92,7 +92,7 @@ def test_process_image_file_issues(tmp_path, exists):
     assert not has_changed
 
 
-def test_main(tmp_path, image_with_metadata):
+def test_main(tmp_path, image_with_metadata, capsys):
     """Test that cli.main() returns the number of files altered."""
     file_without_metadata = tmp_path / 'clean.png'
     file_without_metadata.touch()
@@ -101,6 +101,8 @@ def test_main(tmp_path, image_with_metadata):
 
     assert files_changed == 1
 
+    assert capsys.readouterr().out.strip().endswith(str(image_with_metadata))
+
 
 def test_cli_version(capsys):
     """Confirm that --version works."""