diff --git a/.gitignore b/.gitignore index ace7ba2..4296f83 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,3 @@ pyqso.debug build/ docs/build -ADIF.test_*.adi -Cabrillo.test_*.log -Logbook.test_*.db -Printer.test_*.pdf diff --git a/tests/res/ADIF.test_read.adi b/tests/res/ADIF.test_read.adi new file mode 100644 index 0000000..cdf6044 --- /dev/null +++ b/tests/res/ADIF.test_read.adi @@ -0,0 +1,4 @@ +Some test ADI data. + +TEST40mCW +201303221955 diff --git a/tests/res/ADIF.test_read_alphabet.adi b/tests/res/ADIF.test_read_alphabet.adi new file mode 100644 index 0000000..e2f3337 --- /dev/null +++ b/tests/res/ADIF.test_read_alphabet.adi @@ -0,0 +1,2 @@ +Some test ADI data. +ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/tests/res/ADIF.test_read_capitalisation.adi b/tests/res/ADIF.test_read_capitalisation.adi new file mode 100644 index 0000000..0380016 --- /dev/null +++ b/tests/res/ADIF.test_read_capitalisation.adi @@ -0,0 +1,2 @@ +Some test ADI data. +test diff --git a/tests/res/ADIF.test_read_header_only.adi b/tests/res/ADIF.test_read_header_only.adi new file mode 100644 index 0000000..59b1a09 --- /dev/null +++ b/tests/res/ADIF.test_read_header_only.adi @@ -0,0 +1 @@ +Some test ADI data. diff --git a/tests/res/ADIF.test_read_multiple.adi b/tests/res/ADIF.test_read_multiple.adi new file mode 100644 index 0000000..a5de8a1 --- /dev/null +++ b/tests/res/ADIF.test_read_multiple.adi @@ -0,0 +1,9 @@ +Some test ADI data. + +TEST40mCW +201303221955 + +TEST2ABC20mSSB +201502270820 + +HELLO2mFM201502270832 diff --git a/tests/test_adif.py b/tests/test_adif.py index 16bb826..5401643 100644 --- a/tests/test_adif.py +++ b/tests/test_adif.py @@ -18,6 +18,7 @@ # along with PyQSO. If not, see . import unittest +import os from pyqso.adif import * @@ -31,14 +32,8 @@ class TestADIF(unittest.TestCase): def test_read(self): """ Check that a single ADIF record can be read and parsed correctly. """ - f = open("ADIF.test_read.adi", 'w') - f.write("""Some test ADI data. - -TEST40mCW -201303221955""") - f.close() - - records = self.adif.read("ADIF.test_read.adi") + path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "res", "ADIF.test_read.adi") + records = self.adif.read(path) expected_records = [{'TIME_ON': '1955', 'BAND': '40m', 'CALL': 'TEST', 'MODE': 'CW', 'QSO_DATE': '20130322'}] print("Imported records: ", records) print("Expected records: ", expected_records) @@ -48,19 +43,8 @@ class TestADIF(unittest.TestCase): def test_read_multiple(self): """ Check that multiple ADIF records can be read and parsed correctly. """ - f = open("ADIF.test_read_multiple.adi", 'w') - f.write("""Some test ADI data. - -TEST40mCW -201303221955 - -TEST2ABC20mSSB -201502270820 - -HELLO2mFM201502270832""") - f.close() - - records = self.adif.read("ADIF.test_read_multiple.adi") + path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "res", "ADIF.test_read_multiple.adi") + records = self.adif.read(path) expected_records = [{'TIME_ON': '1955', 'BAND': '40m', 'CALL': 'TEST', 'MODE': 'CW', 'QSO_DATE': '20130322'}, {'TIME_ON': '0820', 'BAND': '20m', 'CALL': 'TEST2ABC', 'MODE': 'SSB', 'QSO_DATE': '20150227'}, {'TIME_ON': '0832', 'BAND': '2m', 'CALL': 'HELLO', 'MODE': 'FM', 'QSO_DATE': '20150227'}] print("Imported records: ", records) print("Expected records: ", expected_records) @@ -71,12 +55,8 @@ class TestADIF(unittest.TestCase): def test_read_alphabet(self): """ Check that none of the letters of the alphabet are ignored during parsing. """ - f = open("ADIF.test_read_alphabet.adi", 'w') - f.write("""Some test ADI data. -ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ""") - f.close() - - records = self.adif.read("ADIF.test_read_alphabet.adi") + path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "res", "ADIF.test_read_alphabet.adi") + records = self.adif.read(path) expected_records = [{'CALL': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'}] print("Imported records: ", records) print("Expected records: ", expected_records) @@ -86,12 +66,8 @@ class TestADIF(unittest.TestCase): def test_read_capitalisation(self): """ Check that the CALL field is capitalised correctly. """ - f = open("ADIF.test_read_capitalisation.adi", 'w') - f.write("""Some test ADI data. -test""") - f.close() - - records = self.adif.read("ADIF.test_read_capitalisation.adi") + path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "res", "ADIF.test_read_capitalisation.adi") + records = self.adif.read(path) expected_records = [{'CALL': 'TEST'}] print("Imported records: ", records) print("Expected records: ", expected_records) @@ -101,11 +77,8 @@ class TestADIF(unittest.TestCase): def test_read_header_only(self): """ Check that no records are read in if the ADIF file only contains header information. """ - f = open("ADIF.test_read_header_only.adi", 'w') - f.write("""Some test ADI data.""") - f.close() - - records = self.adif.read("ADIF.test_read_header_only.adi") + path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "res", "ADIF.test_read_header_only.adi") + records = self.adif.read(path) expected_records = [] print("Imported records: ", records) print("Expected records: ", expected_records)