Commit 795a6bc9 authored by Manuel Günther's avatar Manuel Günther

Unified driver API; added tests for path and reverse commands; fixed small bugs.

parent 7d1eaf5b
......@@ -18,10 +18,10 @@ def dumplist(args):
r = db.objects(
protocol=args.protocol,
purposes=args.purposes,
purposes=args.purpose,
model_ids=args.client,
groups=args.groups,
classes=args.classes
groups=args.group,
classes=args.sclass
)
output = sys.stdout
......@@ -137,33 +137,33 @@ class Interface(BaseInterface):
# the "dumplist" action
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('-p', '--protocol', dest="protocol", default='', help="if given, limits the check to a particular subset of the data that corresponds to the given protocol.", choices=db.protocol_names() if db.is_valid() else ())
parser.add_argument('-u', '--purposes', dest="purposes", default='', help="if given, this value will limit the output files to those designed for the given purposes.", choices=db.purposes() if db.is_valid() else ())
parser.add_argument('-C', '--client', dest="client", default=None, type=int, help="if given, limits the dump to a particular client.", choices=db.model_ids() if db.is_valid else ())
parser.add_argument('-g', '--groups', dest="groups", default='', help="if given, this value will limit the output files to those belonging to a particular protocolar group.", choices=db.groups() if db.is_valid() else ())
parser.add_argument('-c', '--classes', dest="classes", default='', help="if given, this value will limit the output files to those belonging to the given classes.", choices=('client', 'impostor', ''))
parser.add_argument('-d', '--directory', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('-p', '--protocol', help="if given, limits the check to a particular subset of the data that corresponds to the given protocol.", choices=db.protocol_names() if db.is_valid() else ())
parser.add_argument('-u', '--purpose', help="if given, this value will limit the output files to those designed for the given purposes.", choices=db.purposes() if db.is_valid() else ())
parser.add_argument('-C', '--client', type=int, help="if given, limits the dump to a particular client.", choices=db.model_ids() if db.is_valid else ())
parser.add_argument('-g', '--group', help="if given, this value will limit the output files to those belonging to a particular protocolar group.", choices=db.groups() if db.is_valid() else ())
parser.add_argument('-c', '--class', dest="sclass", help="if given, this value will limit the output files to those belonging to the given classes.", choices=('client', 'impostor'))
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=dumplist) #action
# the "checkfiles" action
parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('-d', '--directory', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=checkfiles) #action
# adds the "reverse" command
parser = subparsers.add_parser('reverse', help=reverse.__doc__)
parser.add_argument('path', nargs='+', type=str, help="one or more path stems to look up. If you provide more than one, files which cannot be reversed will be omitted from the output.")
parser.add_argument('path', nargs='+', help="one or more path stems to look up. If you provide more than one, files which cannot be reversed will be omitted from the output.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=reverse) #action
# adds the "path" command
parser = subparsers.add_parser('path', help=path.__doc__)
parser.add_argument('-d', '--directory', dest="directory", default='', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('-d', '--directory', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('id', nargs='+', type=int, help="one or more file ids to look up. If you provide more than one, files which cannot be found will be omitted from the output. If you provide a single id to lookup, an error message will be printed if the id does not exist in the database. The exit status will be non-zero in such case.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=path) #action
......
......@@ -492,7 +492,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
return ProtocolPurpose.purpose_choices
def paths(self, ids, prefix='', suffix=''):
def paths(self, ids, prefix=None, suffix=None):
"""Returns a full file paths considering particular file ids, a given
directory and an extension
......@@ -532,6 +532,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
"""
fobj = self.query(File).filter(File.path.in_(paths))
retval = []
for p in paths:
retval.extend([k.id for k in fobj if k.path == p])
return retval
......
......@@ -55,6 +55,7 @@ class MobioDatabaseTest(unittest.TestCase):
# Check T-Norm models
self.assertEqual(len(db.tmodels()), 192)
def test02_protocols(self):
db = Database()
......@@ -67,6 +68,7 @@ class MobioDatabaseTest(unittest.TestCase):
self.assertEqual(len(db.subworld_names()), 3)
self.assertTrue(db.has_subworld('onethird'))
def test03_files(self):
db = Database()
......@@ -121,27 +123,20 @@ class MobioDatabaseTest(unittest.TestCase):
self.assertEqual(len(db.objects(protocol='male', groups='eval', purposes='probe', classes='client', model_ids=1)), 105)
self.assertEqual(len(db.objects(protocol='male', groups='eval', purposes='probe', classes='impostor', model_ids=1)), 3885)
# T-Norm and Z-Norm files
self.assertEqual(len(db.tobjects()), 960)
self.assertEqual(len(db.tobjects(model_ids=('204_01',))), 5)
self.assertEqual(len(db.zobjects()), 3072)
self.assertEqual(len(db.zobjects(model_ids=(204,))), 192)
def test04_manage_dumplist_1(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('mobio dumplist --self-test'.split()), 0)
def test05_manage_dumplist_2(self):
def test04_driver_api(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('mobio dumplist --self-test'.split()), 0)
self.assertEqual(main('mobio dumplist --protocol=male --class=client --group=dev --purpose=enrol --client=115 --self-test'.split()), 0)
self.assertEqual(main('mobio checkfiles --self-test'.split()), 0)
self.assertEqual(main('mobio reverse m313/m313_01_p01_i0_0 --self-test'.split()), 0)
self.assertEqual(main('mobio path 21132 --self-test'.split()), 0)
self.assertEqual(main('mobio dumplist --protocol=male --classes=client --groups=dev --purposes=enrol --self-test'.split()), 0)
def test06_manage_checkfiles(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('mobio checkfiles --self-test'.split()), 0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment