def create_parser() -> FileAwareParser: """ Create a command line parser :return: parser """ parser = FileAwareParser( description="Clear data from FHIR observation fact table", prog="removefacts", use_defaults=False) parser.add_argument("-ss", "--sourcesystem", metavar="SOURCE SYSTEM CODE", help="Sourcesystem code") parser.add_argument( "-u", "--uploadid", metavar="UPLOAD IDENTIFIER", help="Upload identifer -- uniquely identifies this batch", type=int, nargs='*') add_connection_args(parser, strong_config_file=False) parser.add_argument( "-p", "--testprefix", metavar="SS PREFIX", help= f"Sourcesystem_cd prefix for test suite functions (Default: {default_test_prefix}" ) parser.add_argument("--testlist", help="List leftover test suite entries", action="store_true") parser.add_argument("--removetestlist", help="Remove leftover test suite entries", action="store_true") return parser
def parse_args(argv: List[str]) -> Optional[argparse.Namespace]: """ Parse i2b2 connection arguments :param argv: Arguments :return: parsed arguments if success otherwise nothing """ parser = FileAwareParser(description="Iterate over table_access table", prog="table_access") add_connection_args(parser) opts, _ = parser.parse_known_args(parser.decode_file_args(argv)) return opts
def test_decodefileargs1(self): from i2b2model.sqlsupport.dbconnection import add_connection_args parser = FileAwareParser() parser.add_argument('-mv', '--metadatavoc', help="Unused") add_connection_args(parser) opts = parser.parse_args( parser.decode_file_args( f"--conf {os.path.join(self.conf_dir, 'db_conf')}".split())) self.assertEqual("postgresql+psycopg2://localhost:5432/i2b2", opts.crcdb) self.assertEqual("postgresql+psycopg2://localhost:5433/i2b2", opts.ontodb) self.assertEqual("postgresql+psycopg2://localhost:5431/i2b2", opts.dburl) self.assertEqual('../tests/data/fhir_metadata_vocabulary', opts.metadatavoc) self.assertEqual('postgres', opts.user) self.assertEqual('postgres', opts.password)
def test_decodefileargs2(self): from i2b2model.sqlsupport.dbconnection import add_connection_args parser = FileAwareParser() add_connection_args(parser) opts = process_parsed_args( parser.parse_args( parser.decode_file_args("--conf {}".format( os.path.join(self.conf_dir, 'db_conf_2')).split())), None, False) self.assertEqual("postgresql+psycopg2://localhost:5431/i2b2", opts.crcdb) self.assertEqual("user2", opts.crcuser) self.assertEqual("password1", opts.crcpassword) self.assertEqual("postgresql+psycopg2://localhost:5433/i2b2", opts.ontodb) self.assertEqual("postgresql+psycopg2://localhost:5431/i2b2", opts.dburl) self.assertEqual('user1', opts.ontouser) self.assertEqual('password1', opts.ontopassword)
def create_parser() -> FileAwareParser: """ Create a parser for unit testing """ parser = FileAwareParser(description="Test connection") parser.add_argument("-l", "--load", help="Load i2b2 SQL tables", action="store_true") parser.add_argument( "-u", "--uploadid", metavar="Upload identifier", help="Upload identifer -- uniquely identifies this batch", type=int, required=True) return add_connection_args(parser)