[chirp_devel] [PATCH 03/22] Fix style issues in unit tests (#2355)

Zach Welch
Sat Feb 28 22:54:40 PST 2015


# HG changeset patch
# User Zach Welch <zach at mandolincreekfarm.com>
# Fake Node ID 0769bf2afdf672f5b5b00bfbbba88a5e24f19214

Fix style issues in unit tests (#2355)

The memedit unit tests needed an exception, as that module uses a lambda
to fake localization when importing the UI module.

diff --git a/tests/unit/test_import_logic.py b/tests/unit/test_import_logic.py
index eff56b5..ecd9aa9 100644
--- a/tests/unit/test_import_logic.py
+++ b/tests/unit/test_import_logic.py
@@ -3,6 +3,7 @@ from chirp import import_logic
 from chirp import chirp_common
 from chirp import errors
 
+
 class FakeRadio(chirp_common.Radio):
     def __init__(self, arg):
         self.POWER_LEVELS = list([chirp_common.PowerLevel('lo', watts=5),
@@ -26,9 +27,11 @@ class FakeRadio(chirp_common.Radio):
         rf.has_rx_dtcs = self.HAS_RX_DTCS
         return rf
 
+
 class FakeDstarRadio(FakeRadio, chirp_common.IcomDstarSupport):
     pass
 
+
 class DstarTests(base.BaseTest):
     def _test_ensure_has_calls(self, mem,
                                ini_urcalls, ini_rptcalls,
@@ -87,7 +90,7 @@ class DstarTests(base.BaseTest):
         exp_rptcalls[4] = mem.dv_rpt2call
         self._test_ensure_has_calls(mem, ini_urcalls, ini_rptcalls,
                                     exp_urcalls, exp_rptcalls)
-        
+
     def test_ensure_has_calls_urcall_full(self):
         mem = chirp_common.DVMemory()
         mem.dv_urcall = 'KK7DS'
@@ -138,7 +141,8 @@ class DstarTests(base.BaseTest):
                           self._test_ensure_has_calls,
                           mem, ini_urcalls, ini_rptcalls,
                           exp_urcalls, exp_rptcalls)
-        
+
+
 class ImportFieldTests(base.BaseTest):
     def test_import_name(self):
         mem = chirp_common.Memory()
@@ -164,7 +168,7 @@ class ImportFieldTests(base.BaseTest):
 
     def test_import_power_no_dst(self):
         radio = FakeRadio(None)
-        src_rf = radio.get_features() # Steal a copy before we stub out
+        src_rf = radio.get_features()  # Steal a copy before we stub out
         self.mox.StubOutWithMock(radio, 'get_features')
         radio.get_features().AndReturn(chirp_common.RadioFeatures())
         self.mox.ReplayAll()
@@ -244,7 +248,6 @@ class ImportFieldTests(base.BaseTest):
         import_logic._import_mode(radio, None, mem)
         self.assertEqual(mem.mode, 'AM')
 
-
     def test_import_mode_invalid(self):
         radio = FakeRadio(None)
         radio.MODES.remove('AM')
diff --git a/tests/unit/test_memedit_edits.py b/tests/unit/test_memedit_edits.py
index c717013..decd667 100644
--- a/tests/unit/test_memedit_edits.py
+++ b/tests/unit/test_memedit_edits.py
@@ -26,17 +26,20 @@ class TestEdits(base.BaseTest):
         memedit.MemoryEditor.ed_tone_field(editor, None, 'path', None, col)
 
     def _test_auto_tone_mode(self, col, exp_tmode, exp_cmode):
+        cross_exp_cmode = (exp_tmode == "Cross" and exp_cmode or None)
+
         # No tmode -> expected tmode, maybe requires cross mode change
         self._test_tone_column_change(col, exp_tmode=exp_tmode,
-            exp_cmode=(exp_tmode=="Cross" and exp_cmode or None))
+                                      exp_cmode=cross_exp_cmode)
 
         # Expected tmode does not re-set tmode, may change cmode
         self._test_tone_column_change(col, ini_tmode=exp_tmode,
-            exp_cmode=(exp_tmode=="Cross" and exp_cmode or None))
+                                      exp_cmode=cross_exp_cmode)
 
         # Invalid tmode -> expected, may change cmode
-        self._test_tone_column_change(col, ini_tmode="foo", exp_tmode=exp_tmode,
-            exp_cmode=(exp_tmode=="Cross" and exp_cmode or None))
+        self._test_tone_column_change(col, ini_tmode="foo",
+                                      exp_tmode=exp_tmode,
+                                      exp_cmode=cross_exp_cmode)
 
         # Expected cmode does not re-set cmode
         self._test_tone_column_change(col, ini_tmode="Cross",
diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py
index e130a95..ccc4308 100644
--- a/tests/unit/test_settings.py
+++ b/tests/unit/test_settings.py
@@ -16,6 +16,7 @@
 from tests.unit import base
 from chirp import settings
 
+
 class TestSettingValues(base.BaseTest):
     def _set_and_test(self, rsv, *values):
         for value in values:
@@ -26,7 +27,7 @@ class TestSettingValues(base.BaseTest):
         for value in values:
             self.assertRaises(settings.InvalidValueError,
                               rsv.set_value, value)
-        
+
     def test_radio_setting_value_integer(self):
         value = settings.RadioSettingValueInteger(0, 10, 5)
         self.assertEqual(value.get_value(), 5)
@@ -65,6 +66,7 @@ class TestSettingValues(base.BaseTest):
             pass
 
         value = settings.RadioSettingValueString(0, 5, "foo", autopad=False)
+
         def test_validate(val):
             if val == "bar":
                 raise TestException()
@@ -80,6 +82,7 @@ class TestSettingValues(base.BaseTest):
         value.set_value(True)
         self.assertTrue(value.changed())
 
+
 class TestSettingContainers(base.BaseTest):
     def test_radio_setting_group(self):
         s1 = settings.RadioSetting("s1", "Setting 1")
@@ -97,6 +100,7 @@ class TestSettingContainers(base.BaseTest):
         self.assertEqual(group.values(), [s1, s2, s3])
         self.assertEqual(group.keys(), ["s1", "s2", "s3"])
         self.assertEqual([x for x in group], [s1, s2, s3])
+
         def set_dupe():
             group["s3"] = s3
         self.assertRaises(KeyError, set_dupe)
@@ -125,6 +129,7 @@ class TestSettingContainers(base.BaseTest):
 
         rs = settings.RadioSetting("foo", "Foo")
         self.assertFalse(rs.has_apply_callback())
+
         def test_cb(setting, data1, data2):
             self.assertEqual(setting, rs)
             self.assertEqual(data1, "foo")
diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist
index 1df7274..5cf2b23 100644
--- a/tools/cpep8.blacklist
+++ b/tools/cpep8.blacklist
@@ -93,8 +93,5 @@
 ./csvdump/csvapp.py
 ./csvdump/csvdump.py
 ./share/make_supported.py
-./tests/unit/test_import_logic.py
-./tests/unit/test_memedit_edits.py
-./tests/unit/test_settings.py
 ./tools/bitdiff.py
 ./tools/img2thd72.py
diff --git a/tools/cpep8.exceptions b/tools/cpep8.exceptions
index 394634f..3aafd1d 100644
--- a/tools/cpep8.exceptions
+++ b/tools/cpep8.exceptions
@@ -3,3 +3,4 @@
 # of style rules to ignore in that file.  This mechanism should be used
 # sparingly and as a measure of last resort.
 ./tests/run_tests	E402
+./tests/unit/test_memedit_edits.py	E402




More information about the chirp_devel mailing list