def test_correctArgsShort(self) -> None: argsList = ['L', 'p', 'i.txt', 'o.json'] sys.argv[1:] = setUp(argsList) args = ArgParse.ArgParse() self.assertName(argsList[0], args.userName) self.assertName(argsList[1], args.printerName) self.assertPath(argsList[2], args.inputFile) self.assertPath(argsList[3], args.outputFile)
def test_correctArgs(self) -> None: argsList = ['UserName123', 'printer1@asdf', 'input.txt', 'out.json'] sys.argv[1:] = setUp(argsList) args = ArgParse.ArgParse() self.assertName(argsList[0], args.userName) self.assertName(argsList[1], args.printerName) self.assertPath(argsList[2], args.inputFile) self.assertPath(argsList[3], args.outputFile)
def test_emptyOutFile(self) -> None: argsList = ['Lukas', 'printer1', 'input.txt', ''] sys.argv[1:] = setUp(argsList) try: ArgParse.ArgParse() except ValueError: self.assertTrue(True) else: self.assertTrue(False)
def test_wrongOutFormat(self) -> None: argsList = ['UserName123', 'printer1@asdf', 'input.txt', 'out.jsn'] sys.argv[1:] = setUp(argsList) try: ArgParse.ArgParse() except TypeError: self.assertTrue(True) else: self.assertTrue(False)
def main() -> None: try: args = ArgParse.ArgParse() args.parseArgs() IOHandle.IOHandle(args) except ValueError: print('No script parameter can be empty!', file=stderr) except TypeError: print('The output file must be the JSON format (.json)', file=stderr) except FileNotFoundError: print('The input file could not be found!', file=stderr) except Exception: print('An unexpected error has occured!', file=stderr)
def parse_cli(config_list): args = ap.ArgParse(lst=config_list) fetch = args.parse()