Esempio n. 1
0
def db_path(temp_dir, db_filename, items):
    database = module.Database()
    [database.add(k, v) for k, v in items.items()]
    db_path = temp_dir.join(db_filename)
    database.save(db_path)
    print("\t MODULE_FIXTURE: db_path ", db_path)
    return db_path
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser(
        prog='PROG',
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="See '<command> --help' to read about a specific sub-command.")
    parser.add_argument(
        "-v",
        "--verbosity",
        type=str,
        default='ERROR',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
        help="Sets the logging level (default: %(default)s)")
    subparsers = parser.add_subparsers(dest='command', help='Sub-commands')

    # Arguments for subcommand ADD
    add_parser = subparsers.add_parser('add', help='ADD help text')
    add_parser.set_defaults(func=add_command)
    add_parser.add_argument("key",
                            nargs=1,
                            type=str,
                            action='store',
                            help="Key used to identify the stored value")
    add_parser.add_argument("value",
                            action='store',
                            nargs=1,
                            type=str,
                            help="Value to store in the database")

    # Arguments for subcommand GET
    get_parser = subparsers.add_parser('get', help='GET help text')
    get_parser.set_defaults(func=get_command)
    get_parser.add_argument("key",
                            nargs=1,
                            type=str,
                            action='store',
                            help="Key used to identify the value to retrieve")

    # Arguments for subcommand DEL
    del_parser = subparsers.add_parser('del', help='DEL help text')
    del_parser.set_defaults(func=del_command)
    del_parser.add_argument("key",
                            nargs=1,
                            type=str,
                            action='store',
                            help="Key used to identify the value to delete")

    # Arguments for subcommand LIST
    list_parser = subparsers.add_parser('list', help='LIST help text')
    list_parser.set_defaults(func=list_command)

    # Return arguments
    args = parser.parse_args()
    if args.command is not None:
        run_command(module.Database(), args)
    else:
        parser.print_help()
    sys.exit(0)  # Shell return 0 == success
Esempio n. 3
0
def empty_database():
    """Returns a completely new and empty database"""
    print("\t FUNCTION_FIXTURE: new_database")
    return module.Database()
Esempio n. 4
0
def class_database(items):
    """Returns a class shared database with some items already"""
    print("\t CLASS_FIXTURE: class_database")
    database = module.Database()
    [database.add(k, v) for k, v in items.items()]
    return database
Esempio n. 5
0
 def test_load_db(self):
     """Tests the method to delete a key"""
     db = module.Database()
     self.assertEqual(db.load("test_db2.mydb"), None)
     self.assertEqual(db._dict, {'a': 1, 'b': 2})
Esempio n. 6
0
 def setUp(self):
     """DB file contruction with some key-values."""
     database = module.Database()
     database._dict = {'a': 1, 'b': 2}
     database.save("test_db2.mydb")
Esempio n. 7
0
 def setUp(self):
     """DB contruction with some key-values."""
     database = module.Database()
     database._dict = {'a': 1, 'b': 2}
     self.db = database