示例#1
0
def main():
    logging.basicConfig(level=logging.INFO, format='%(levelname)-8s: %(message)s')
    parser = version.ArgumentParser(description=__doc__.strip())
    parser.add_argument('filename', help='Beancount filename')
    parser.add_argument('output_directory', help='Output directory for the tutorial files')
    args = parser.parse_args()
    rootdir = test_utils.find_repository_root(__file__)
    bindir = "{} {}/bin/".format(sys.executable, rootdir)

    for report_name, command_template in COMMANDS:
        logging.info('Generating %s: %s', report_name, command_template)
        output_filename = path.join(args.output_directory, '{}.output'.format(report_name))
        errors_filename = path.join(args.output_directory, '{}.errors'.format(report_name))
        with open(output_filename, 'w') as output_file:
            with open(errors_filename, 'w') as errors_file:
                command = command_template.format(bindir=bindir, filename=args.filename)
                pipe = subprocess.Popen(command,
                                        env=test_utils.subprocess_env(),
                                        shell=True,
                                        stdout=output_file,
                                        stderr=errors_file)
                pipe.communicate()
                if pipe.returncode != 0:
                    with open(errors_filename) as efile:
                        errors = efile.read()
                    raise RuntimeError(
                        "Error running '{}': exit with {}; errors: {}".format(
                            command, pipe.returncode, errors))

        if path.getsize(errors_filename) == 0:
            os.remove(errors_filename)

    return 0
示例#2
0
def main():
    logging.basicConfig(level=logging.INFO, format='%(levelname)-8s: %(message)s')
    parser = argparse.ArgumentParser(description=__doc__.strip())
    parser.add_argument('filename', help='Beancount filename')
    parser.add_argument('output_directory', help='Output directory for the tutorial files')
    args = parser.parse_args()

    for report_name, command_template in COMMANDS:
        logging.info('Generating %s: %s', report_name, command_template)
        output_filename = path.join(args.output_directory, '{}.output'.format(report_name))
        errors_filename = path.join(args.output_directory, '{}.errors'.format(report_name))
        with open(output_filename, 'w') as output_file:
            with open(errors_filename, 'w') as errors_file:
                command = command_template.format(args.filename)
                pipe = subprocess.Popen(command,
                                        env=test_utils.subprocess_env(),
                                        shell=True,
                                        stdout=output_file,
                                        stderr=errors_file)
                pipe.communicate()
                assert pipe.returncode == 0, pipe.returncode

        if path.getsize(errors_filename) == 0:
            os.remove(errors_filename)

    return 0
示例#3
0
 def test_parse_stdin(self):
     code = ('import beancount.parser.parser_test as p; '
             'p.TestParserInputs.parse_stdin()')
     pipe = subprocess.Popen([sys.executable, '-c', code, __file__],
                             env=test_utils.subprocess_env(),
                             stdin=subprocess.PIPE)
     output, errors = pipe.communicate(self.INPUT.encode('utf-8'))
     self.assertEqual(0, pipe.returncode)
示例#4
0
    def test_returns_example_script(self):
        # We want to ensure the example script doesn't break unexpectedly, so
        # call it from the unit tests.
        script_name = path.join(test_utils.find_repository_root(__file__),
                                'examples', 'example.returns.py')
        self.assertTrue(path.exists(script_name))

        pipe = subprocess.Popen(script_name,
                                env=test_utils.subprocess_env(),
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, errors = pipe.communicate()
        self.assertEqual(0, pipe.returncode)
        self.assertFalse(errors)
        self.assertRegex(output, b'Returns for')
示例#5
0
    def test_returns_invoke_via_main(self):
        # We want to ensure we can call the module and it doesn't fail.
        example_filename = path.join(test_utils.find_repository_root(__file__),
                                     'examples', 'example.beancount')
        self.assertTrue(path.exists(example_filename))

        command = [sys.executable, '-m', 'beancount.projects.returns',
                   example_filename,
                   'Assets:US:ETrade', 'Expenses:Financial:Commissions']
        pipe = subprocess.Popen(command,
                                env=test_utils.subprocess_env(),
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, errors = pipe.communicate()
        self.assertEqual(0, pipe.returncode)
        self.assertRegex(output, b'Total returns')
        self.assertRegex(output, b'Averaged annual returns')