Пример #1
0
 def testBatch(self):
     "It must be possible to read from a file using the batch method"
     infp = StringIO('3\n4\n+\np\n')
     outfp = StringIO()
     c = Calculator(outfp=outfp)
     c.batch(infp)
     self.assertEqual('7\n', outfp.getvalue())
Пример #2
0
                          debug=args.debug)

        if args.startupFile:
            try:
                with open(args.startupFile) as f:
                    exec(f.read(), globals(), calc._variables)
            except FileNotFoundError:
                calc.err('Startup file %s not found' % args.startupFile)

        interactive = setupReadline()

        if args.files:
            if all(os.path.exists(f) or f == '-' for f in args.files):
                # All arguments are existing files (or are '-', for stdin).
                for filename in args.files:
                    if filename == '-':
                        calc.repl(args.prompt)
                    else:
                        with open(filename) as fp:
                            calc.batch(fp, False)
            else:
                # Execute the command line as a set of commands, following
                # great suggestion by David Pattinson.
                calc.batch((' '.join(args.files), ), args.finalPrint)
                if args.stdin:
                    calc.repl(args.prompt)
        elif interactive:
            calc.repl(args.prompt)
        else:
            calc.batch(sys.stdin, args.finalPrint)