Re: Beancount development: how to run all unittests in all directories

100 views
Skip to first unread message

Martin Blais

unread,
Aug 13, 2020, 9:08:24 AM8/13/20
to Beancount
make test

which is

bergamot [git|v2]:~/p/beancount$ make -n test
python3 -m pytest beancount

In v3 (master):
bazel test ...





On Thu, Aug 13, 2020 at 9:00 AM Chary Chary <char...@gmail.com> wrote:
Dear all,

can anybody suggest how one can run all beancount unittests (as they are spread across many folders)?

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/fa186f31-aba1-4e0a-ab4c-80a7bd22b84cn%40googlegroups.com.

Chary Chary

unread,
Aug 13, 2020, 10:23:37 AM8/13/20
to Beancount
Martin,

thanks! I get few errors. Is this OK?

===============================
================================================================= FAILURES =================================================================
____________________________________________________ TestWillReport.test_create_report _____________________________________________________

self = <beancount.projects.will_test.TestWillReport testMethod=test_create_report>
entries = [Open(meta={'filename': '<string>', 'lineno': 5, 'institution': 'Bank of America', 'address': '100 North Tryon Street,... '<string>', 'lineno': 30}, date=datetime.date(2010, 1, 1), account='Income:Misc', currencies=None, booking=None), ...]
_ = []
options_map = {'account_current_conversions': 'Conversions:Current', 'account_current_earnings': 'Earnings:Current', 'account_previous_balances': 'Opening-Balances', 'account_previous_conversions': 'Conversions:Previous', ...}

    @loader.load_doc()
    def test_create_report(self, entries, _, options_map):
        """
          option "title" "Report Creation Test"
   
          ;; Two accounts in the same institution.
          2010-01-01 open Assets:US:BofA
            institution: "Bank of America"
            address: "100 North Tryon Street,  Charlotte, NC 28255"
            phone: "1.800.933.6262"
            website: "https://www.bankofamerica.com"
   
          2010-01-01 open Assets:US:BofA:Checking
            type: "Checking Account"
            number: "43865450874"
   
          2010-01-01 open Assets:US:BofA:Savings
            type: "Savings Account"
            number: "83470650273"
   
          ;; An an account with a zero balance.
          2010-01-01 open Liabilities:US:BofA:CreditCard
            institution: "Bank of America"
            number: "3478.4744.2339.0011"
   
          ;; With a non-zeo liabilities account.
          2010-01-01 open Liabilities:US:Chase:CreditCard
            institution: "Chase Manhattan Bank"
            address: "National Bank By Mail, P O Box 36520, Louisville, KY 40233-6520"
            number: "7654.0754.9375.0489"
   
          2010-01-01 open Income:Misc
   
          2014-02-03 *
            Assets:US:BofA:Checking          3400.00 USD
            Assets:US:BofA:Savings           1200.00 USD
            Liabilities:US:Chase:CreditCard  -820.00 USD
            Income:Misc
   
        """
        report = will.create_report(entries, options_map)
        text = will.format_xhtml_report(report, options_map)
>       with open('/tmp/index.html', 'w') as infile:
E       PermissionError: [Errno 13] Permission denied: '/tmp/index.html'

beancount/projects/will_test.py:139: PermissionError
__________________________________________________ TestSetup.test_sdist_includes_c_files ___________________________________________________

self = <beancount.scripts.setup_test.TestSetup testMethod=test_sdist_includes_c_files>

    @unittest.skipIf(is_bazel_build(), "Cannot setup within Bazel.")
    def test_sdist_includes_c_files(self):
        # Clean previously built "build" output.
        rootdir = test_utils.find_repository_root(__file__)
        subprocess.check_call(
            [sys.executable, 'setup.py', 'sdist', '--dist-dir', self.installdir],
            cwd=rootdir, shell=False,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        files = os.listdir(self.installdir)
        self.assertEqual(1, len(files))
        targz = path.join(self.installdir, files[0])
   
        # Find the set of expected header & C files.
        exp_filenames = set()
        for root, dirs, files in os.walk(path.join(rootdir, 'beancount')):
            for filename in files:
                if re.match(r'.*\.[hc]$', filename):
                    exp_filenames.add(path.join(root[len(rootdir)+1:], filename))
   
        # Find the set of packaged files in the source distribution.
        tar = tarfile.open(targz)
        tar_filenames = set(re.sub('^.*?{}'.format(os.sep), '', info.name)
                            for info in tar
                            if re.match(r'.*\.[hc]$', info.name))
   
        # Check that all the expected files are present.
>       self.assertLessEqual(exp_filenames, tar_filenames)
E       AssertionError: {'beancount/parser/parser.c', 'beancount/parser/grammar.c', 'beancount/parser/macros.h', 'beancount/parser/tokens_test.c', 'beancount/parser/parser.h', 'beancount/parser/grammar.h', 'beancount/parser/tokens.h', 'beancount/defs.h', 'beancount/ccore/account.h', 'beancount/parser/lexer.c', 'beancount/parser/lexer.h'} not less than or equal to {'beancount/parser/parser.c', 'beancount/parser/grammar.c', 'beancount/parser/macros.h', 'beancount/parser/tokens_test.c', 'beancount/parser/parser.h', 'beancount/parser/grammar.h', 'beancount/parser/tokens.h', 'beancount/parser/lexer.c', 'beancount/parser/lexer.h'}

beancount/scripts/setup_test.py:161: AssertionError
========================================================= short test summary info ==========================================================
FAILED beancount/projects/will_test.py::TestWillReport::test_create_report - PermissionError: [Errno 13] Permission denied: '/tmp/index.h...
FAILED beancount/scripts/setup_test.py::TestSetup::test_sdist_includes_c_files - AssertionError: {'beancount/parser/parser.c', 'beancount...
===================================== 2 failed, 1495 passed, 23 skipped, 2 xfailed in 78.39s (0:01:18) =====================================
make: *** [Makefile:147: test] Error 1



=============================

Chary Chary

unread,
Aug 13, 2020, 10:44:22 AM8/13/20
to Beancount
I see it complains about permissions to ''tmp/index.html', but I ran it with root privileges.

Chary Chary

unread,
Aug 13, 2020, 4:21:20 PM8/13/20
to Beancount
Sorry,

above errors were on the master branch. On the v2 there is just one error with setup_test.py

=========================================================== FAILURES ============================================================
_____________________________________________________ TestSetup.test_setup ______________________________________________________

self = <beancount.scripts.setup_test.TestSetup testMethod=test_setup>


    @unittest.skipIf(is_bazel_build(), "Cannot setup within Bazel.")
    def test_setup(self):
        # We need to create the installation target directory and have our
        # PYTHONPATH set on it in order for setuptools to work properly in a
        # temporary installation directory. Otherwise it fails and spits out a
        # large error message with instructions on how to work with setuptools.
        site_packages_path = path.join(
            self.installdir,
            'lib/python{vi.major:d}.{vi.minor:d}/site-packages'.format(
                vi=sys.version_info))
        os.makedirs(site_packages_path)
>       self.run_setup(self.installdir, {'PYTHONPATH': site_packages_path})

beancount/scripts/setup_test.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
beancount/scripts/setup_test.py:86: in run_setup
    self.assertEqual(0, pipe.returncode, stderr)
E   AssertionError: 0 != 1 : b"/usr/lib/python3/dist-packages/setuptools/dist.py:473: UserWarning: Normalizing '2.3.2-dev' to '2.3.2.dev0'\n  warnings.warn(\nerror: could not create 'build/bdist.linux-x86_64/egg': Permission denied\n"
==================================================== short test summary info ====================================================
FAILED beancount/scripts/setup_test.py::TestSetup::test_setup - AssertionError: 0 != 1 : b"/usr/lib/python3/dist-packages/setu...
=============================== 1 failed, 1680 passed, 24 skipped, 2 xfailed in 108.89s (0:01:48) ===============================

Daniele Nicolodi

unread,
Aug 14, 2020, 12:39:34 AM8/14/20
to bean...@googlegroups.com
On 13/08/2020 14:21, Chary Chary wrote:
> On the v2 there is just one error with setup_test.py

This is strange, like in the other errors you reported for master, it
seems like the tests are not able to write temporary files or, in this
case write files in a temporary folder.

On which platform is this happening? Which version of python? Can you
report on the exact procedure you use to run the tests, starting from
how you got the source code?

Thank you.

Cheers,
Dan

Chary Chary

unread,
Aug 14, 2020, 4:43:31 AM8/14/20
to Beancount
Thanks for looking at this!

I did it once again the whole procedure now, and now everything is working. Not sure what was different back then (may be I did sudo python3 setup.py build_ext -i ). 

Any way, for record,  this is how I did it:

==========================================
git clone https://github.com/beancount/beancount.git
cd beancount
git checkout v2

#then I updated PATH and PYTHONPATH to point to right places
# and now tests:

python3 setup.py build_ext -i
make test

Result is:

=========== 1681 passed, 24 skipped, 2 xfailed

===========================================

I am using Ubuntu 20.04.1 LTS with   Python 3.8.2

Chary Chary

unread,
Sep 7, 2020, 7:43:23 AM9/7/20
to Beancount
I understand, that Windows is not an officially supported platform, nevertheless I have logged a bug, regarding usage of unittest 

Reply all
Reply to author
Forward
0 new messages