diff --git a/photograb/main.py b/photograb/main.py index b498397..d772d87 100644 --- a/photograb/main.py +++ b/photograb/main.py @@ -48,7 +48,7 @@ def main(opts): # TODO: gracefully fail if camera is not writable. pass - # Store some shared context + # Store some shared context camera_files = camera.read_content() new_files = {} if opts.grab: # Grab new files from camera @@ -80,6 +80,7 @@ def main(opts): camera.remove_content(deleted) if opts.wipe_card: # Remove all files from camera + print_success("Wiping camera...") for ext in backups: to_delete = camera_files.filter_by_ext(ext) camera.remove_content(to_delete) diff --git a/photograb/test/test_main.py b/photograb/test/test_main.py index 7cc5bd1..0acb2d3 100644 --- a/photograb/test/test_main.py +++ b/photograb/test/test_main.py @@ -2,18 +2,11 @@ import unittest import os -from configparser import ConfigParser from ..main import parser, main class TestMain(unittest.TestCase): - _default = {'Camera': './sandbox/sdcard'} - _config = { - 'jpg': [('Import', './sandbox/import'), - ('Backup', './sandbox/jpg')], - 'mp4': [('Backup', './sandbox/mp4')], - } _paths = [ './sandbox/', './sandbox/sdcard', @@ -24,7 +17,9 @@ class TestMain(unittest.TestCase): './sandbox/mp4/.trash', ] _files = { - './sandbox/sdcard/': ['a.jpg', 'b.jpg', 'c.jpg', 'd.mp4', 'e.mp4'], + './sandbox/sdcard/': [ + 'a.jpg', 'b.jpg', 'c.jpg', + 'd.mp4', 'e.mp4', 'z.txt'], './sandbox/jpg/': ['a.jpg', ], './sandbox/mp4/': ['d.mp4', ], } @@ -33,17 +28,10 @@ class TestMain(unittest.TestCase): for p in self._paths: if not os.path.exists(p): os.mkdir(p) - for path, files in self._files.items(): for f in files: open(path + f, "w").close() - self.config = ConfigParser(defaults=self._default) - for key, options in self._config.items(): - self.config.add_section(key) - for k, v in options: - self.config.set(key, k, v) - def tearDown(self): for f in self._files['./sandbox/sdcard/']: for path in list(self._files) + ['./sandbox/import/']: @@ -52,15 +40,14 @@ class TestMain(unittest.TestCase): for p in reversed(self._paths): if os.path.exists(p): os.rmdir(p) - self.config = None def test_grab_only(self): opts = parser.parse_args(['--grab', ]) main(opts) for folder, should_exist in [ - ('jpg', [True, True, True, False, False]), - ('mp4', [False, False, False, True, True]), - ('import', [False, True, True, False, False]), + ('jpg', [True, True, True, False, False, False]), + ('mp4', [False, False, False, True, True, False]), + ('import', [False, True, True, False, False, False]), ]: for i, expected in enumerate(should_exist): filename = f"./sandbox/{folder}/" @@ -85,4 +72,15 @@ class TestMain(unittest.TestCase): pass def test_wipe_card(self): - pass + opts = parser.parse_args(['--wipe-card', ]) + main(opts) + for i, should_exist in enumerate( + [False, False, False, False, False, True] + ): + filename = self._files['./sandbox/sdcard/'][i] + with self.subTest(f=filename): + self.assertEqual( + os.path.exists( + "./sandbox/sdcard/" + filename + ), + should_exist)