adds test
This commit is contained in:
@@ -48,7 +48,7 @@ def main(opts):
|
|||||||
# TODO: gracefully fail if camera is not writable.
|
# TODO: gracefully fail if camera is not writable.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Store some shared context
|
# Store some shared context
|
||||||
camera_files = camera.read_content()
|
camera_files = camera.read_content()
|
||||||
new_files = {}
|
new_files = {}
|
||||||
if opts.grab: # Grab new files from camera
|
if opts.grab: # Grab new files from camera
|
||||||
@@ -80,6 +80,7 @@ def main(opts):
|
|||||||
camera.remove_content(deleted)
|
camera.remove_content(deleted)
|
||||||
|
|
||||||
if opts.wipe_card: # Remove all files from camera
|
if opts.wipe_card: # Remove all files from camera
|
||||||
|
print_success("Wiping camera...")
|
||||||
for ext in backups:
|
for ext in backups:
|
||||||
to_delete = camera_files.filter_by_ext(ext)
|
to_delete = camera_files.filter_by_ext(ext)
|
||||||
camera.remove_content(to_delete)
|
camera.remove_content(to_delete)
|
||||||
|
|||||||
@@ -2,18 +2,11 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
from configparser import ConfigParser
|
|
||||||
from ..main import parser, main
|
from ..main import parser, main
|
||||||
|
|
||||||
|
|
||||||
class TestMain(unittest.TestCase):
|
class TestMain(unittest.TestCase):
|
||||||
|
|
||||||
_default = {'Camera': './sandbox/sdcard'}
|
|
||||||
_config = {
|
|
||||||
'jpg': [('Import', './sandbox/import'),
|
|
||||||
('Backup', './sandbox/jpg')],
|
|
||||||
'mp4': [('Backup', './sandbox/mp4')],
|
|
||||||
}
|
|
||||||
_paths = [
|
_paths = [
|
||||||
'./sandbox/',
|
'./sandbox/',
|
||||||
'./sandbox/sdcard',
|
'./sandbox/sdcard',
|
||||||
@@ -24,7 +17,9 @@ class TestMain(unittest.TestCase):
|
|||||||
'./sandbox/mp4/.trash',
|
'./sandbox/mp4/.trash',
|
||||||
]
|
]
|
||||||
_files = {
|
_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/jpg/': ['a.jpg', ],
|
||||||
'./sandbox/mp4/': ['d.mp4', ],
|
'./sandbox/mp4/': ['d.mp4', ],
|
||||||
}
|
}
|
||||||
@@ -33,17 +28,10 @@ class TestMain(unittest.TestCase):
|
|||||||
for p in self._paths:
|
for p in self._paths:
|
||||||
if not os.path.exists(p):
|
if not os.path.exists(p):
|
||||||
os.mkdir(p)
|
os.mkdir(p)
|
||||||
|
|
||||||
for path, files in self._files.items():
|
for path, files in self._files.items():
|
||||||
for f in files:
|
for f in files:
|
||||||
open(path + f, "w").close()
|
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):
|
def tearDown(self):
|
||||||
for f in self._files['./sandbox/sdcard/']:
|
for f in self._files['./sandbox/sdcard/']:
|
||||||
for path in list(self._files) + ['./sandbox/import/']:
|
for path in list(self._files) + ['./sandbox/import/']:
|
||||||
@@ -52,15 +40,14 @@ class TestMain(unittest.TestCase):
|
|||||||
for p in reversed(self._paths):
|
for p in reversed(self._paths):
|
||||||
if os.path.exists(p):
|
if os.path.exists(p):
|
||||||
os.rmdir(p)
|
os.rmdir(p)
|
||||||
self.config = None
|
|
||||||
|
|
||||||
def test_grab_only(self):
|
def test_grab_only(self):
|
||||||
opts = parser.parse_args(['--grab', ])
|
opts = parser.parse_args(['--grab', ])
|
||||||
main(opts)
|
main(opts)
|
||||||
for folder, should_exist in [
|
for folder, should_exist in [
|
||||||
('jpg', [True, True, True, False, False]),
|
('jpg', [True, True, True, False, False, False]),
|
||||||
('mp4', [False, False, False, True, True]),
|
('mp4', [False, False, False, True, True, False]),
|
||||||
('import', [False, True, True, False, False]),
|
('import', [False, True, True, False, False, False]),
|
||||||
]:
|
]:
|
||||||
for i, expected in enumerate(should_exist):
|
for i, expected in enumerate(should_exist):
|
||||||
filename = f"./sandbox/{folder}/"
|
filename = f"./sandbox/{folder}/"
|
||||||
@@ -85,4 +72,15 @@ class TestMain(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_wipe_card(self):
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user