Skip to content

Commit

Permalink
[electrum] let unittest discover all test cases
Browse files Browse the repository at this point in the history
Summary:
This does not change the behavior of the `test_runner.py` script which was already discovering the tests.

It fixes running the test suites individually when the `suite()` function was not maintained, e.g.:
```
python -m electrumabc.tests.test_wallet
```

From the unitest.main doc:

> The defaultTest argument is either the name of a single test or an iterable of test names to run if no test names are specified via argv. If not specified or None and no test names are provided via argv, all tests found in module are run.

Depends on D14442

Test Plan:
```
python test_runner.py
python -m electrumabc.tests.test_wallet
python -m electrumabc.tests.test_transaction
```
Check that all test cases are run (same number of tests before and after this change in the case of `test_runner.py`).

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D14443
  • Loading branch information
PiRK committed Sep 4, 2023
1 parent aab7dbb commit 57176a0
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 109 deletions.
12 changes: 1 addition & 11 deletions electrum/electrumabc/tests/test_avalanche.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,5 @@ def test_raises_deserializationerror(self):
Delegation.from_hex(one_level_dg_hex[:-2])


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestAvalancheProofBuilder))
test_suite.addTest(loadTests(TestAvalancheProofFromHex))
test_suite.addTest(loadTests(TestAvalancheDelegationBuilder))
test_suite.addTest(loadTests(TestAvalancheDelegationFromHex))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
13 changes: 1 addition & 12 deletions electrum/electrumabc/tests/test_bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,16 +655,5 @@ def test_encrypt(self):
# Success!


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestBitcoin))
test_suite.addTest(loadTests(TestBitcoinTestnet))
test_suite.addTest(loadTests(TestXprvXpub))
test_suite.addTest(loadTests(TestKeyImport))
test_suite.addTest(loadTests(TestBip38))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,5 @@ def test_preprocess(self):
self.assertEqual(args.url, bip21_uri)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestCommands))
test_suite.addTest(loadTests(TestArgParser))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
9 changes: 1 addition & 8 deletions electrum/electrumabc/tests/test_consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,5 @@ def test_get_unsigned_transactions(self):
self.assertEqual(total_fee, total_size * FEERATE)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestConsolidateCoinSelection))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
12 changes: 1 addition & 11 deletions electrum/electrumabc/tests/test_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,5 @@ def test_seed_type(self):
self.assertEqual(_type, mnemo.seed_type_name(seed_words), msg=seed_words)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestNewMnemonic))
test_suite.addTest(loadTests(TestOldMnemonic))
test_suite.addTest(loadTests(TestBIP39Checksum))
test_suite.addTest(loadTests(TestSeeds))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_schnorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,5 @@ def test_jacobi(self):
self.assertEqual(jac_1(a, n), jac_2(a, n), msg=(a, n))


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestSchnorr))
test_suite.addTest(loadTests(TestBlind))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,5 @@ class something:
self.assertEqual({}, result)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestSimpleConfig))
test_suite.addTest(loadTests(TestUserConfig))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,5 @@ def synchronous_get(self, arg):
return self.unspent


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestBCDataStream))
test_suite.addTest(loadTests(TestTransaction))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_uint256.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,5 @@ def test_deserialize(self):
self.assertIsInstance(o, UInt256)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestBaseBlob))
test_suite.addTest(loadTests(TestUInt256))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
14 changes: 1 addition & 13 deletions electrum/electrumabc/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,5 @@ def test_parse_URI_parameter_polution(self):
)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestFormatSatoshisLocaleC))
test_suite.addTest(loadTests(TestFormatSatoshisLocaleFr))
test_suite.addTest(loadTests(TestFormatSatoshisLocaleDe))
test_suite.addTest(loadTests(TestFormatSatoshisLocaleAr_SA))
test_suite.addTest(loadTests(TestFormatSatoshisLocalezh_CN))
test_suite.addTest(loadTests(TestUtil))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()
10 changes: 1 addition & 9 deletions electrum/electrumabc/tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,5 @@ def test_sweep_dust(self):
self.assertEqual(tx.get_fee(), fee)


def suite():
test_suite = unittest.TestSuite()
loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
test_suite.addTest(loadTests(TestCreateRestoreWallet))
test_suite.addTest(loadTests(TestWalletStorage))
return test_suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
unittest.main()

0 comments on commit 57176a0

Please sign in to comment.