def setUp(self): example_filename = path.join(test_utils.find_repository_root(__file__), 'examples', 'example.beancount') global entries, errors, options_map # pylint: disable=invalid-name entries, errors, options_map = loader.load(example_filename) assert not errors
def run_setup(self, installdir, extra_env=None): """Run setup.py with the given extra environment variables. Args: installdir: A string, the name of the temporary directory to install into. extra_env: A dict, extra environment variables to set in the subprocess. """ rootdir = test_utils.find_repository_root(__file__) # Clean previously built "build" output. command = [sys.executable, 'setup.py', 'clean', '--all'] subprocess_env = os.environ.copy() if extra_env: subprocess_env.update(extra_env) pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=rootdir, env=subprocess_env) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr) # Install in a temporary directory. command = [ sys.executable, 'setup.py', 'install', '--prefix={}'.format(installdir) ] subprocess_env = os.environ.copy() if extra_env: subprocess_env.update(extra_env) pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=rootdir, env=subprocess_env) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr) self.assertTrue(path.exists(path.join(installdir, 'bin'))) self.assertTrue(path.exists(path.join(installdir, 'lib'))) self.assertGreater(len(list(os.walk(installdir))), 20) # Find bin and library dirs. bindir = path.join(installdir, 'bin') libdir = path.join(installdir, 'lib') while path.basename(libdir) != 'site-packages': libdir = path.join(libdir, os.listdir(libdir)[0]) # Run at least with the --help option for all the installed tools. for binname in os.listdir(bindir): # Skip tools with optional dependencies. if not binname.startswith('bean-'): continue command = [path.join(bindir, binname), '--help'] pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'PYTHONPATH': path.join(libdir)}, cwd=rootdir) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr) # Run some basic commands using the main tools from newly installed version. example_filename = path.join(rootdir, 'examples/example.beancount') # Run bean-check. command = [path.join(bindir, 'bean-check'), '-v', example_filename] pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'PYTHONPATH': path.join(libdir)}, cwd=rootdir) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr) # Run bean-report. command = [ path.join(bindir, 'bean-report'), example_filename, 'balsheet' ] pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'PYTHONPATH': path.join(libdir)}, cwd=rootdir) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr) # Run bean-query. command = [ path.join(bindir, 'bean-query'), example_filename, 'balances;' ] pipe = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'PYTHONPATH': path.join(libdir)}, cwd=rootdir) stdout, stderr = pipe.communicate() self.assertEqual(0, pipe.returncode, stderr)
def test_example(self): # Run the SQL translation on our pretty substantial example file. root_dir = test_utils.find_repository_root(__file__) filename = path.join(root_dir, 'examples/example.beancount') self.convert_to_sql(filename)
def scrape(self, filename, **extra): abs_filename = path.join(test_utils.find_repository_root(__file__), 'examples', filename) web.scrape_webapp(abs_filename, self.check_page_okay, test_utils.get_test_port(), self.ignore_regexp, **extra)