|
| 1 | +from unittest import TestCase |
| 2 | +from unittest.mock import patch |
| 3 | +from github import Github |
| 4 | + |
| 5 | +from ledgered.github import AppRepository |
| 6 | + |
| 7 | + |
| 8 | +class TestAppRepository(TestCase): |
| 9 | + def setUp(self): |
| 10 | + self.gh = Github() |
| 11 | + |
| 12 | + def test__set_variants_VARIANTS(self): |
| 13 | + param = "COIN" |
| 14 | + coins = ["COIN1", "COIN2"] |
| 15 | + AppRepository.makefile = f"@echo VARIANTS {param} {' '.join(coins)}" |
| 16 | + with patch("github.Repository.Repository", AppRepository): |
| 17 | + app_repo = self.gh.get_repo("LedgerHQ/ledgered") |
| 18 | + self.assertIsNone(app_repo._variant_param) |
| 19 | + self.assertListEqual(app_repo._variant_values, []) |
| 20 | + |
| 21 | + self.assertIsNone(app_repo._set_variants()) |
| 22 | + |
| 23 | + self.assertEqual(app_repo._variant_param, param) |
| 24 | + self.assertListEqual(app_repo._variant_values, coins) |
| 25 | + |
| 26 | + def test__set_variants_VARIANTS_variable(self): |
| 27 | + param = "COIN" |
| 28 | + AppRepository.makefile = f"@echo VARIANTS {param} $(COINS)" |
| 29 | + with patch("github.Repository.Repository", AppRepository): |
| 30 | + app_repo = self.gh.get_repo("LedgerHQ/ledgered") |
| 31 | + self.assertIsNone(app_repo._variant_param) |
| 32 | + self.assertListEqual(app_repo._variant_values, []) |
| 33 | + |
| 34 | + self.assertIsNone(app_repo._set_variants()) |
| 35 | + |
| 36 | + # `$(COIN)` can not be interpreted from Ledgered, so the variants can not be parsed |
| 37 | + self.assertIsNone(app_repo._variant_param) |
| 38 | + self.assertListEqual(app_repo._variant_values, []) |
| 39 | + |
| 40 | + def test__set_variants_standard(self): |
| 41 | + param = "COIN" |
| 42 | + coins = ["COIN1", "COIN2"] |
| 43 | + AppRepository.makefile = f"VARIANT_PARAM={param}\nVARIANT_VALUES = {' '.join(coins)}" |
| 44 | + with patch("github.Repository.Repository", AppRepository): |
| 45 | + app_repo = self.gh.get_repo("LedgerHQ/ledgered") |
| 46 | + self.assertIsNone(app_repo._variant_param) |
| 47 | + self.assertListEqual(app_repo._variant_values, []) |
| 48 | + |
| 49 | + self.assertIsNone(app_repo._set_variants()) |
| 50 | + |
| 51 | + self.assertEqual(app_repo._variant_param, param) |
| 52 | + self.assertListEqual(app_repo._variant_values, coins) |
| 53 | + |
| 54 | + def test__set_variants_standard_variable(self): |
| 55 | + param = "COIN" |
| 56 | + AppRepository.makefile = f"VARIANT_PARAM= {param}\nVARIANT_VALUES = $(COINS)" |
| 57 | + with patch("github.Repository.Repository", AppRepository): |
| 58 | + app_repo = self.gh.get_repo("LedgerHQ/ledgered") |
| 59 | + self.assertIsNone(app_repo._variant_param) |
| 60 | + self.assertListEqual(app_repo._variant_values, []) |
| 61 | + |
| 62 | + self.assertIsNone(app_repo._set_variants()) |
| 63 | + |
| 64 | + # `$(COIN)` can not be interpreted from Ledgered, so the variants can not be parsed |
| 65 | + self.assertIsNone(app_repo._variant_param) |
| 66 | + self.assertListEqual(app_repo._variant_values, []) |
0 commit comments