moves parser from __main__, updates tests
This commit is contained in:
@@ -26,27 +26,8 @@
|
|||||||
__version__ = "0.1"
|
__version__ = "0.1"
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from .main import main
|
from .main import parser, main
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog='Photograb')
|
|
||||||
parser.add_argument('-a', '--all',
|
|
||||||
action="store_true",
|
|
||||||
help="Perform all actions. Equivalent to -gst")
|
|
||||||
parser.add_argument('-g', '--grab',
|
|
||||||
action="store_true",
|
|
||||||
help="Grab files from camera")
|
|
||||||
parser.add_argument('-s', '--sync',
|
|
||||||
action="store_true",
|
|
||||||
help="Synchronize deleted files")
|
|
||||||
parser.add_argument('-t', '--clean-trash',
|
|
||||||
action="store_true",
|
|
||||||
help="Clean the bins")
|
|
||||||
parser.add_argument('-u', '--update-card',
|
|
||||||
action="store_true",
|
|
||||||
help="Use with sync, also update the camera card")
|
|
||||||
parser.add_argument('--wipe-card',
|
|
||||||
action="store_true",
|
|
||||||
help="Wipe the camera card")
|
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
|
|
||||||
# If no options are given, print the help message
|
# If no options are given, print the help message
|
||||||
|
|||||||
@@ -1,9 +1,30 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
import argparse
|
||||||
from .store import Content, Store
|
from .store import Content, Store
|
||||||
from .config import load_config, BadConfiguration
|
from .config import load_config, BadConfiguration
|
||||||
from .utils import print_error, print_success
|
from .utils import print_error, print_success
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(prog='Photograb')
|
||||||
|
parser.add_argument('-a', '--all',
|
||||||
|
action="store_true",
|
||||||
|
help="Perform all actions. Equivalent to -gst")
|
||||||
|
parser.add_argument('-g', '--grab',
|
||||||
|
action="store_true",
|
||||||
|
help="Grab files from camera")
|
||||||
|
parser.add_argument('-s', '--sync',
|
||||||
|
action="store_true",
|
||||||
|
help="Synchronize deleted files")
|
||||||
|
parser.add_argument('-t', '--clean-trash',
|
||||||
|
action="store_true",
|
||||||
|
help="Clean the bins")
|
||||||
|
parser.add_argument('-u', '--update-card',
|
||||||
|
action="store_true",
|
||||||
|
help="Use with sync, also update the camera card")
|
||||||
|
parser.add_argument('--wipe-card',
|
||||||
|
action="store_true",
|
||||||
|
help="Wipe the camera card")
|
||||||
|
|
||||||
|
|
||||||
def find_imported():
|
def find_imported():
|
||||||
""" Finds files imported into the gallery """
|
""" Finds files imported into the gallery """
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
Camera = /media/sdcard
|
Camera = ./sandbox/sdcard
|
||||||
|
|
||||||
[jpg]
|
[jpg]
|
||||||
Import = /home/artus/Dev/python/sandbox/import/
|
Import = ./sandbox/import/
|
||||||
Backup = /home/artus/Dev/python/sandbox/Picture/
|
Backup = ./sandbox/jpg/
|
||||||
|
|
||||||
[mp4]
|
[mp4]
|
||||||
Backup = /home/artus/Dev/python/sandbox/Video/
|
Backup = ./sandbox/mp4/
|
||||||
|
|||||||
88
photograb/test/test_main.py
Normal file
88
photograb/test/test_main.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
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',
|
||||||
|
'./sandbox/import',
|
||||||
|
'./sandbox/jpg',
|
||||||
|
'./sandbox/jpg/.trash',
|
||||||
|
'./sandbox/mp4',
|
||||||
|
'./sandbox/mp4/.trash',
|
||||||
|
]
|
||||||
|
_files = {
|
||||||
|
'./sandbox/sdcard/': ['a.jpg', 'b.jpg', 'c.jpg', 'd.mp4', 'e.mp4'],
|
||||||
|
'./sandbox/jpg/': ['a.jpg', ],
|
||||||
|
'./sandbox/mp4/': ['d.mp4', ],
|
||||||
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
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/']:
|
||||||
|
if os.path.exists(path + f):
|
||||||
|
os.unlink(path + f)
|
||||||
|
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]),
|
||||||
|
]:
|
||||||
|
for i, expected in enumerate(should_exist):
|
||||||
|
filename = f"./sandbox/{folder}/"
|
||||||
|
filename += self._files['./sandbox/sdcard/'][i]
|
||||||
|
result = os.path.exists(filename)
|
||||||
|
with self.subTest(tested=filename, expected=expected):
|
||||||
|
if expected:
|
||||||
|
self.assertTrue(result)
|
||||||
|
else:
|
||||||
|
self.assertFalse(result)
|
||||||
|
|
||||||
|
def test_sync_only(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_update_card_has_no_effect_without_sync(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_clean_only(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_all_ops(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_wipe_card(self):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user