Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit 173f18b

Browse files
committed
Fixed generating missing header fields in adi.dump*()
Added test for unmodified data_dict
1 parent 2d7019b commit 173f18b

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/adif_file/adi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def dumpi(data_dict: dict, comment: str = 'ADIF export by ' + __proj_name__) ->
219219
elif p.upper() == 'USERDEFS':
220220
for i, u in enumerate(data_dict['HEADER'][p], 1):
221221
data += pack(f'USERDEF{i}', u['userdef'], u['dtype']) + '\n'
222-
for p in default.items():
222+
for p in default:
223223
data += pack(p, default[p]) + '\n'
224224
data += '<EOH>'
225225
yield data

test/test_dumpadi.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,43 @@ def test_30_dump_a_file(self):
123123

124124
os.remove(temp_file)
125125

126+
def test_40_dump_no_change(self):
127+
adi_dict = {
128+
'HEADER': {'PROGRAMID': 'TProg',
129+
'PROGRAMVERSION': '1',
130+
'CREATED_TIMESTAMP': '1234'},
131+
'RECORDS': [{'TEST1': 'test',
132+
'TEST2': 'test2'},
133+
{'TEST1': 'test3',
134+
'TEST2': 'test4'}]
135+
}
136+
adi_dict_sav = adi_dict.copy()
137+
138+
adi_exp = '''ADIF export by PyADIF-File
139+
<PROGRAMID:5>TProg
140+
<PROGRAMVERSION:1>1
141+
<CREATED_TIMESTAMP:4>1234
142+
<ADIF_VER:5>3.1.4
143+
<EOH>
144+
145+
<TEST1:4>test <TEST2:5>test2
146+
<EOR>
147+
148+
<TEST1:5>test3 <TEST2:5>test4
149+
<EOR>'''
150+
151+
temp_file = get_file_path('testdata/~test.adi')
152+
153+
adif_file.adi.dump(temp_file, adi_dict)
154+
self.assertDictEqual(adi_dict_sav, adi_dict)
155+
156+
self.assertTrue(os.path.isfile(temp_file))
157+
158+
with open(temp_file) as af:
159+
self.assertEqual(adi_exp, af.read())
160+
161+
os.remove(temp_file)
162+
126163

127164
if __name__ == '__main__':
128165
unittest.main()

0 commit comments

Comments
 (0)