mirror of
https://github.com/gryf/wicd.git
synced 2026-01-03 20:34:17 +01:00
Merged with experimental (1.6) branch (r229).
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
def run_tests():
|
||||
import unittest
|
||||
test_suite = unittest.TestSuite()
|
||||
@@ -6,4 +5,7 @@ def run_tests():
|
||||
import testwnettools
|
||||
test_suite.addTest(testwnettools.suite())
|
||||
|
||||
unittest.TextTestRunner(verbosity=5).run(test_suite)
|
||||
import testmisc
|
||||
test_suite.addTest(testmisc.suite())
|
||||
|
||||
unittest.TextTestRunner(verbosity=2).run(test_suite)
|
||||
|
||||
145
tests/testmisc.py
Normal file
145
tests/testmisc.py
Normal file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
from wicd import misc
|
||||
|
||||
class TestMisc(unittest.TestCase):
|
||||
def test_misc_run(self):
|
||||
output = misc.Run(['echo', 'hi']).strip()
|
||||
self.assertEquals('hi', output)
|
||||
|
||||
def test_valid_ip_1(self):
|
||||
self.assertTrue(misc.IsValidIP('0.0.0.0'))
|
||||
|
||||
def test_valid_ip_2(self):
|
||||
self.assertTrue(misc.IsValidIP('255.255.255.255'))
|
||||
|
||||
def test_valid_ip_3(self):
|
||||
self.assertTrue(misc.IsValidIP('10.0.1.1'))
|
||||
|
||||
def test_invalid_ip_1(self):
|
||||
self.assertFalse(misc.IsValidIP('-10.0.-1.-1'))
|
||||
|
||||
def test_invalid_ip_2(self):
|
||||
self.assertFalse(misc.IsValidIP('256.0.0.1'))
|
||||
|
||||
def test_invalid_ip_3(self):
|
||||
self.assertFalse(misc.IsValidIP('1000.0.0.1'))
|
||||
|
||||
def test_run_valid_regex(self):
|
||||
import re
|
||||
regex = re.compile('.*(ABC.EFG).*')
|
||||
found = misc.RunRegex(regex, '01234ABCDEFG56789')
|
||||
self.assertEquals(found, 'ABCDEFG')
|
||||
|
||||
def test_run_invalid_regex(self):
|
||||
import re
|
||||
regex = re.compile('.*(ABC.EFG).*')
|
||||
found = misc.RunRegex(regex, '01234ABCEDFG56789')
|
||||
self.assertEquals(found, None)
|
||||
|
||||
def test_to_boolean_false(self):
|
||||
self.assertFalse(misc.to_bool('False'))
|
||||
|
||||
def test_to_boolean_0(self):
|
||||
self.assertFalse(misc.to_bool('0'))
|
||||
|
||||
def test_to_boolean_true(self):
|
||||
self.assertTrue(misc.to_bool('True'))
|
||||
|
||||
def test_to_boolean_true(self):
|
||||
self.assertTrue(misc.to_bool('1'))
|
||||
|
||||
def test_noneify_1(self):
|
||||
self.assertEquals(misc.Noneify('None'), None)
|
||||
|
||||
def test_noneify_2(self):
|
||||
self.assertEquals(misc.Noneify(''), None)
|
||||
|
||||
def test_noneify_3(self):
|
||||
self.assertEquals(misc.Noneify(None), None)
|
||||
|
||||
def test_noneify_4(self):
|
||||
self.assertFalse(misc.Noneify('False'))
|
||||
|
||||
def test_noneify_5(self):
|
||||
self.assertFalse(misc.Noneify('0'))
|
||||
|
||||
def test_noneify_6(self):
|
||||
self.assertFalse(misc.Noneify(False))
|
||||
|
||||
def test_noneify_7(self):
|
||||
self.assertTrue(misc.Noneify('True'))
|
||||
|
||||
def test_noneify_8(self):
|
||||
self.assertTrue(misc.Noneify('1'))
|
||||
|
||||
def test_noneify_9(self):
|
||||
self.assertTrue(misc.Noneify(True))
|
||||
|
||||
def test_noneify_10(self):
|
||||
self.assertEquals(misc.Noneify('randomtext'), 'randomtext')
|
||||
|
||||
def test_noneify_11(self):
|
||||
self.assertEquals(misc.Noneify(5), 5)
|
||||
|
||||
def test_none_to_string_1(self):
|
||||
self.assertEquals(misc.noneToString(None), 'None')
|
||||
|
||||
def test_none_to_string_2(self):
|
||||
self.assertEquals(misc.noneToString(''), 'None')
|
||||
|
||||
def test_none_to_string_3(self):
|
||||
self.assertEquals(misc.noneToString(None), 'None')
|
||||
|
||||
####################################################################
|
||||
# misc.to_unicode actually converts to utf-8, which is type str #
|
||||
####################################################################
|
||||
|
||||
def test_to_unicode_1(self):
|
||||
self.assertEquals(misc.to_unicode('邪悪'), '邪悪')
|
||||
|
||||
def test_to_unicode_2(self):
|
||||
self.assertEquals(misc.to_unicode(u'邪悪'), '邪悪')
|
||||
|
||||
def test_to_unicode_3(self):
|
||||
self.assertEquals(misc.to_unicode(u'abcdef'), 'abcdef')
|
||||
|
||||
def test_to_unicode_4(self):
|
||||
self.assertEquals(type(misc.to_unicode('abcdef'.encode('latin-1'))), str)
|
||||
|
||||
def test_to_unicode_5(self):
|
||||
self.assertEquals(misc.to_unicode("berkåk"), "berkåk")
|
||||
|
||||
def test_to_unicode_6(self):
|
||||
self.assertEquals(misc.to_unicode('berk\xe5k'), "berkåk")
|
||||
|
||||
def test_none_to_blank_string_1(self):
|
||||
self.assertEquals(misc.noneToBlankString(None), '')
|
||||
|
||||
def test_none_to_blank_string_2(self):
|
||||
self.assertEquals(misc.noneToBlankString('None'), '')
|
||||
|
||||
def test_string_to_none_1(self):
|
||||
self.assertEquals(misc.stringToNone(''), None)
|
||||
|
||||
def test_string_to_none_2(self):
|
||||
self.assertEquals(misc.stringToNone('None'), None)
|
||||
|
||||
def test_string_to_none_3(self):
|
||||
self.assertEquals(misc.stringToNone(None), None)
|
||||
|
||||
def test_string_to_none_4(self):
|
||||
self.assertEquals(misc.stringToNone('abcdef'), 'abcdef')
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
tests = []
|
||||
[ tests.append(test) for test in dir(TestMisc) if test.startswith('test') ]
|
||||
for test in tests:
|
||||
suite.addTest(TestMisc(test))
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -564,14 +564,6 @@ def stringToNone(text):
|
||||
else:
|
||||
return str(text)
|
||||
|
||||
def stringToBoolean(text):
|
||||
""" Turns a string representation of a bool to a boolean if needed. """
|
||||
if text in ("True", "1"):
|
||||
return True
|
||||
if text in ("False", "0"):
|
||||
return False
|
||||
return bool(text)
|
||||
|
||||
def checkboxTextboxToggle(checkbox, textboxes):
|
||||
for textbox in textboxes:
|
||||
textbox.set_sensitive(checkbox.get_active())
|
||||
|
||||
@@ -19,7 +19,7 @@ import gtk
|
||||
import os
|
||||
|
||||
import misc
|
||||
from misc import noneToString, stringToNone, noneToBlankString, stringToBoolean
|
||||
from misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||
import wpath
|
||||
|
||||
language = misc.get_language_list_gui()
|
||||
@@ -526,7 +526,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.script_button.connect("button-press-event", self.edit_scripts)
|
||||
|
||||
# Toggle the default profile checkbox to the correct state.
|
||||
if stringToBoolean(wired.GetWiredProperty("default")):
|
||||
if to_bool(wired.GetWiredProperty("default")):
|
||||
self.chkbox_default_profile.set_active(True)
|
||||
else:
|
||||
self.chkbox_default_profile.set_active(False)
|
||||
@@ -666,7 +666,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.advanced_dialog.prof_name = profile_name
|
||||
|
||||
is_default = wired.GetWiredProperty("default")
|
||||
self.chkbox_default_profile.set_active(stringToBoolean(is_default))
|
||||
self.chkbox_default_profile.set_active(to_bool(is_default))
|
||||
|
||||
def format_entry(self, label):
|
||||
""" Help method for fetching/formatting wired properties. """
|
||||
@@ -728,7 +728,7 @@ class WirelessNetworkEntry(NetworkEntry):
|
||||
self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
|
||||
self.vbox_top.pack_start(self.hbox_status, True, True)
|
||||
|
||||
if stringToBoolean(self.format_entry(networkID, "automatic")):
|
||||
if to_bool(self.format_entry(networkID, "automatic")):
|
||||
self.chkbox_autoconnect.set_active(True)
|
||||
else:
|
||||
self.chkbox_autoconnect.set_active(False)
|
||||
|
||||
Reference in New Issue
Block a user