summaryrefslogtreecommitdiff
path: root/tests/unit/test_csv.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test_csv.py')
-rw-r--r--tests/unit/test_csv.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/unit/test_csv.py b/tests/unit/test_csv.py
index c8428b0..4f1980b 100644
--- a/tests/unit/test_csv.py
+++ b/tests/unit/test_csv.py
@@ -2,7 +2,10 @@ import os
import tempfile
import unittest
+import ddt
+
from chirp import chirp_common
+from chirp import directory
from chirp.drivers import generic_csv
CHIRP_CSV_LEGACY = (
@@ -55,6 +58,10 @@ class TestCSV(unittest.TestCase):
def test_parse_modern(self, output_encoding='utf-8'):
with open(self.testfn, 'w', encoding=output_encoding) as f:
f.write(CHIRP_CSV_MODERN)
+ # Make sure we detect the file
+ with open(self.testfn, 'rb') as f:
+ self.assertTrue(generic_csv.CSVRadio.match_model(
+ f.read(), self.testfn))
csv = generic_csv.CSVRadio(self.testfn)
mem = csv.get_memory(1)
self.assertEqual(1, mem.number)
@@ -72,14 +79,18 @@ class TestCSV(unittest.TestCase):
self.assertEqual('5.0W', str(mem.power))
self.assertIn('UHF calling', mem.comment)
- def test_csv_with_comments(self):
+ def test_csv_with_comments(self, output_encoding='utf-8'):
lines = list(CHIRP_CSV_MODERN.strip().split('\n'))
lines.insert(0, '# This is a comment')
lines.insert(0, '# Test file with comments')
lines.insert(4, '# Test comment in the middle')
lines.append('# Comment at the end')
- with open(self.testfn, 'w', newline='') as f:
+ with open(self.testfn, 'w', newline='', encoding=output_encoding) as f:
f.write('\r\n'.join(lines))
+ # Make sure we detect the file
+ with open(self.testfn, 'rb') as f:
+ self.assertTrue(generic_csv.CSVRadio.match_model(
+ f.read(), self.testfn))
csv = generic_csv.CSVRadio(self.testfn)
mem = csv.get_memory(0)
self.assertEqual(146520000, mem.freq)
@@ -93,6 +104,9 @@ class TestCSV(unittest.TestCase):
def test_parse_modern_bom(self):
self.test_parse_modern(output_encoding='utf-8-sig')
+ def test_parse_modern_bom_with_comments(self):
+ self.test_parse_modern(output_encoding='utf-8-sig')
+
def test_parse_minimal(self):
with open(self.testfn, 'w', encoding='utf-8') as f:
f.write(CHIRP_CSV_MINIMAL)
@@ -186,3 +200,15 @@ class TestCSV(unittest.TestCase):
# its internal state and the following assertion will fail.
m.name = 'bar'
self.assertEqual('foo', radio.get_memory(0).name)
+
+
+@ddt.ddt
+class RTCSV(unittest.TestCase):
+ def _test_open(self, sample):
+ sample_fn = os.path.join(os.path.dirname(__file__), sample)
+ radio = directory.get_radio_by_image(sample_fn)
+ self.assertIsInstance(radio, generic_csv.RTCSVRadio)
+
+ @ddt.data('ft3d', 'ftm400', 'ftm500')
+ def test_sample_file(self, arg):
+ self._test_open('rtcsv_%s.csv' % arg)