Coverage for tests/utils/address_book.py: 98%

59 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1from __future__ import annotations 

2 

3from configparser import ConfigParser 

4from monero import MoneroNetworkType 

5 

6from .daemon_utils import DaemonUtils 

7 

8 

9class AddressBook: 

10 """Address book to use in tests.""" 

11 

12 network_type: MoneroNetworkType = MoneroNetworkType.MAINNET 

13 """Address book's network type.""" 

14 primary_address_1: str = "" 

15 """First test primary address.""" 

16 primary_address_2: str = "" 

17 """Second test primary address.""" 

18 primary_address_3: str = "" 

19 """Third test primary address.""" 

20 primary_address_4: str = "" 

21 """Fourth test primary address.""" 

22 subaddress_1: str = "" 

23 """First test subaddress.""" 

24 subaddress_2: str = "" 

25 """Second test subaddress.""" 

26 subaddress_3: str = "" 

27 """Third test subaddress.""" 

28 subaddress_4: str = "" 

29 """Fourth test subaddress.""" 

30 integrated_1: str = "" 

31 """First integrated subaddress.""" 

32 integrated_2: str = "" 

33 """Second integrated subaddress.""" 

34 integrated_3: str = "" 

35 """Third integrated subaddress.""" 

36 integrated_4: str = "" 

37 """Fourth integrated subaddress.""" 

38 invalid_1: str = "" 

39 """First invalid address.""" 

40 invalid_2: str = "" 

41 """Second invalid address.""" 

42 invalid_3: str = "" 

43 """Third invalid address.""" 

44 

45 @classmethod 

46 def parse(cls, parser: ConfigParser, section: str) -> AddressBook: 

47 """Parse address book configuration. 

48 

49 :param ConfigParser parser: configuration parser. 

50 :param str section: configuration section to parse. 

51 :returns AddressBook: parsed address book. 

52 """ 

53 if not parser.has_section(section): 

54 raise Exception(f"Cannot parse address book entry, invalid section '{section}'") 

55 

56 entry: AddressBook = cls() 

57 entry.primary_address_1 = parser.get(section, 'primary_address_1') 

58 entry.primary_address_2 = parser.get(section, 'primary_address_2') 

59 entry.primary_address_3 = parser.get(section, 'primary_address_3') 

60 entry.primary_address_4 = parser.get(section, 'primary_address_4', fallback='') 

61 entry.subaddress_1 = parser.get(section, 'subaddress_1') 

62 entry.subaddress_2 = parser.get(section, 'subaddress_2') 

63 entry.subaddress_3 = parser.get(section, 'subaddress_3') 

64 entry.subaddress_4 = parser.get(section, 'subaddress_4', fallback='') 

65 entry.integrated_1 = parser.get(section, 'integrated_1') 

66 entry.integrated_2 = parser.get(section, 'integrated_2') 

67 entry.integrated_3 = parser.get(section, 'integrated_3') 

68 entry.integrated_4 = parser.get(section, 'integrated_4', fallback='') 

69 entry.invalid_1 = parser.get(section, 'invalid_1') 

70 entry.invalid_2 = parser.get(section, 'invalid_2') 

71 entry.invalid_3 = parser.get(section, 'invalid_3') 

72 entry.network_type = DaemonUtils.parse_network_type(section) 

73 return entry