lint: convert lint-tests.sh to python #24815
pull KevinMusgrave wants to merge 1 commits into bitcoin:master from KevinMusgrave:lint-tests-python-port changing 2 files +87 −35-
KevinMusgrave commented at 10:05 pm on April 9, 2022: contributorReference issue: https://github.com/bitcoin/bitcoin/issues/24783
-
KevinMusgrave renamed this:
Converted lint-tests.sh to python
lint: converted lint-tests.sh to python
on Apr 9, 2022 -
KevinMusgrave force-pushed on Apr 9, 2022
-
KevinMusgrave renamed this:
lint: converted lint-tests.sh to python
lint: convert lint-tests.sh to python
on Apr 9, 2022 -
DrahtBot added the label Tests on Apr 9, 2022
-
KevinMusgrave commented at 11:59 am on April 11, 2022: contributorMaybe I should replace
grep
,cut
,sort
, anduniq
with python functions -
KevinMusgrave force-pushed on Apr 11, 2022
-
KevinMusgrave force-pushed on Apr 11, 2022
-
KevinMusgrave commented at 10:19 pm on April 11, 2022: contributorOk I converted those functions to python, so the only non-python call is
git grep
. -
KevinMusgrave force-pushed on Apr 11, 2022
-
KevinMusgrave force-pushed on Apr 11, 2022
-
in test/lint/lint-tests.py:3 in 285ee4b00c outdated
0@@ -0,0 +1,76 @@ 1+#!/usr/bin/env python3 2+# 3+# Copyright (c) 2018 The Bitcoin Core developers
vincenzopalazzo commented at 11:33 pm on April 11, 2022:0# Copyright (c) 2018-2022 The Bitcoin Core developers
KevinMusgrave commented at 2:12 pm on April 13, 2022:Fixedvincenzopalazzo commented at 11:35 pm on April 11, 2022: noneKevinMusgrave force-pushed on Apr 13, 2022KevinMusgrave commented at 2:37 pm on April 13, 2022: contributorBelow are example outputs, before and after the change. The only difference is that the new version adds a newline after the “matching names” test, which I think improves readability.
Before (lint-tests.sh):
0The test suite in file src/test/foo_tests.cpp should be named 1"foo_tests". Please make sure the following test suites follow 2that convention: 3 4src/test/banman_tests.cpp:BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup) 5src/test/bip32_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup) 6src/test/blockchain_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup) 7src/test/blockencodings_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, RegTestingSetup) 8Test suite names must be unique. The following test suite names 9appear to be used more than once: 10 11addrman_tests 12base58_tests
After (lint-tests.py):
0The test suite in file src/test/foo_tests.cpp should be named 1"foo_tests". Please make sure the following test suites follow 2that convention: 3 4src/test/banman_tests.cpp:BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup) 5src/test/bip32_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup) 6src/test/blockchain_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup) 7src/test/blockencodings_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, RegTestingSetup) 8 9Test suite names must be unique. The following test suite names 10appear to be used more than once: 11 12addrman_tests 13base58_tests
in test/lint/lint-tests.py:26 in b4125057ba outdated
21+ r"^BOOST_FIXTURE_TEST_SUITE\(", 22+ "--", 23+ "src/test/**.cpp", 24+ "src/wallet/test/**.cpp", 25+ ] 26+ return subprocess.run(command, stdout=subprocess.PIPE, universal_newlines=True)
laanwj commented at 5:45 pm on April 13, 2022:Would prefer to usecheck_output
here. This would make the script automatically fail if the git grep returns an error status. It also autmatically doesstdout=PIPE
and returnsstdout
.
KevinMusgrave commented at 6:24 pm on April 13, 2022:DoneKevinMusgrave force-pushed on Apr 13, 2022KevinMusgrave force-pushed on Apr 13, 2022Eunoia1729 commented at 10:22 pm on April 13, 2022: contributorutACk Not sure but is it a good practise to leave links in the code ?KevinMusgrave commented at 10:28 pm on April 13, 2022: contributorWhen I grab a snippet from stackoverflow, I like to leave a link to credit the author but also in case I want to see the original answer again.Converted lint-tests.sh to python
Use raw string Use re.search instead of grep in check_matching_test_names Replaced bash commands in check_unique_test_names with python commands Use set and sort output Use set comprehension Use .splitlines() Call grep_boost_fixture_test_suite once splitlines() once Fixed copyright date Use check_output() instead of run() add encoding='utf8' Use clearer code for getting duplicates
in test/lint/lint-tests.py:51 in 21b967a67d outdated
46+ 47+ 48+def check_unique_test_names(test_suite_list): 49+ output = [re.search(r"\((.*?),", x) for x in test_suite_list] 50+ output = [x.group(1) for x in output if x is not None] 51+ # find duplicates, see: https://stackoverflow.com/a/9835819
MarcoFalke commented at 11:11 am on April 15, 2022:This is pretty hard to read and the answer actually recommends against using the snippet.
MarcoFalke commented at 11:11 am on April 15, 2022:This is pretty hard to read and the answer actually recommends against using the snippet.
KevinMusgrave commented at 1:41 pm on April 15, 2022:I assume you mean thisoutput = {x for x in output if x in seen or seen.add(x)}
. I thought the comment makes it clear what it does, but I can convert it to a for loop anyway.
KevinMusgrave commented at 2:16 pm on April 15, 2022:I changed it now
KevinMusgrave commented at 2:16 pm on April 15, 2022:Looks like an accidental duplicate reviewKevinMusgrave force-pushed on Apr 15, 2022laanwj commented at 5:27 pm on April 25, 2022: memberTested ACK ae0e06a439e09a7e24dd6198591a588c8df2d529laanwj merged this on Apr 25, 2022laanwj closed this on Apr 25, 2022
sidhujag referenced this in commit ea3961c0ac on Apr 26, 2022DrahtBot locked this on Apr 25, 2023
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 21:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me