Commit 1cf2a065 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Merge heads

parents 31db7c89 fd8fdb96
......@@ -47,9 +47,7 @@ class ConnectionFactoryTests(unittest.TestCase):
self.con.close()
def CheckIsInstance(self):
self.assertTrue(isinstance(self.con,
MyConnection),
"connection is not instance of MyConnection")
self.assertIsInstance(self.con, MyConnection)
class CursorFactoryTests(unittest.TestCase):
def setUp(self):
......@@ -60,9 +58,7 @@ class CursorFactoryTests(unittest.TestCase):
def CheckIsInstance(self):
cur = self.con.cursor(factory=MyCursor)
self.assertTrue(isinstance(cur,
MyCursor),
"cursor is not instance of MyCursor")
self.assertIsInstance(cur, MyCursor)
class RowFactoryTestsBackwardsCompat(unittest.TestCase):
def setUp(self):
......@@ -72,9 +68,7 @@ class RowFactoryTestsBackwardsCompat(unittest.TestCase):
cur = self.con.cursor(factory=MyCursor)
cur.execute("select 4+5 as foo")
row = cur.fetchone()
self.assertTrue(isinstance(row,
dict),
"row is not instance of dict")
self.assertIsInstance(row, dict)
cur.close()
def tearDown(self):
......@@ -87,28 +81,24 @@ class RowFactoryTests(unittest.TestCase):
def CheckCustomFactory(self):
self.con.row_factory = lambda cur, row: list(row)
row = self.con.execute("select 1, 2").fetchone()
self.assertTrue(isinstance(row,
list),
"row is not instance of list")
self.assertIsInstance(row, list)
def CheckSqliteRowIndex(self):
self.con.row_factory = sqlite.Row
row = self.con.execute("select 1 as a, 2 as b").fetchone()
self.assertTrue(isinstance(row,
sqlite.Row),
"row is not instance of sqlite.Row")
self.assertIsInstance(row, sqlite.Row)
col1, col2 = row["a"], row["b"]
self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")
self.assertEqual(col1, 1, "by name: wrong result for column 'a'")
self.assertEqual(col2, 2, "by name: wrong result for column 'a'")
col1, col2 = row["A"], row["B"]
self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")
self.assertEqual(col1, 1, "by name: wrong result for column 'A'")
self.assertEqual(col2, 2, "by name: wrong result for column 'B'")
col1, col2 = row[0], row[1]
self.assertTrue(col1 == 1, "by index: wrong result for column 0")
self.assertTrue(col2 == 2, "by index: wrong result for column 1")
self.assertEqual(col1, 1, "by index: wrong result for column 0")
self.assertEqual(col2, 2, "by index: wrong result for column 1")
def CheckSqliteRowIter(self):
"""Checks if the row object is iterable"""
......@@ -138,8 +128,8 @@ class RowFactoryTests(unittest.TestCase):
row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
self.assertTrue(row_1 == row_1)
self.assertTrue(row_1 == row_2)
self.assertEqual(row_1, row_1)
self.assertEqual(row_1, row_2)
self.assertTrue(row_2 != row_3)
self.assertFalse(row_1 != row_1)
......@@ -161,20 +151,20 @@ class TextFactoryTests(unittest.TestCase):
def CheckUnicode(self):
austria = "sterreich"
row = self.con.execute("select ?", (austria,)).fetchone()
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
def CheckString(self):
self.con.text_factory = bytes
austria = "sterreich"
row = self.con.execute("select ?", (austria,)).fetchone()
self.assertTrue(type(row[0]) == bytes, "type of row[0] must be bytes")
self.assertTrue(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
self.assertEqual(type(row[0]), bytes, "type of row[0] must be bytes")
self.assertEqual(row[0], austria.encode("utf-8"), "column must equal original data in UTF-8")
def CheckCustom(self):
self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
austria = "sterreich"
row = self.con.execute("select ?", (austria,)).fetchone()
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
self.assertTrue(row[0].endswith("reich"), "column must contain original data")
def CheckOptimizedUnicode(self):
......@@ -185,8 +175,8 @@ class TextFactoryTests(unittest.TestCase):
germany = "Deutchland"
a_row = self.con.execute("select ?", (austria,)).fetchone()
d_row = self.con.execute("select ?", (germany,)).fetchone()
self.assertTrue(type(a_row[0]) == str, "type of non-ASCII row must be str")
self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
def tearDown(self):
self.con.close()
......
......@@ -162,7 +162,7 @@ class ProgressTests(unittest.TestCase):
create table bar (a, b)
""")
second_count = len(progress_calls)
self.assertTrue(first_count > second_count)
self.assertGreater(first_count, second_count)
def CheckCancelOperation(self):
"""
......
......@@ -195,7 +195,7 @@ class BaseTest:
def test_constructor(self):
a = array.array(self.typecode)
self.assertEqual(a.typecode, self.typecode)
self.assertTrue(a.itemsize>=self.minitemsize)
self.assertGreaterEqual(a.itemsize, self.minitemsize)
self.assertRaises(TypeError, array.array, self.typecode, None)
def test_len(self):
......@@ -442,39 +442,39 @@ class BaseTest:
def test_cmp(self):
a = array.array(self.typecode, self.example)
self.assertTrue((a == 42) is False)
self.assertTrue((a != 42) is True)
self.assertIs(a == 42, False)
self.assertIs(a != 42, True)
self.assertTrue((a == a) is True)
self.assertTrue((a != a) is False)
self.assertTrue((a < a) is False)
self.assertTrue((a <= a) is True)
self.assertTrue((a > a) is False)
self.assertTrue((a >= a) is True)
self.assertIs(a == a, True)
self.assertIs(a != a, False)
self.assertIs(a < a, False)
self.assertIs(a <= a, True)
self.assertIs(a > a, False)
self.assertIs(a >= a, True)
al = array.array(self.typecode, self.smallerexample)
ab = array.array(self.typecode, self.biggerexample)
self.assertTrue((a == 2*a) is False)
self.assertTrue((a != 2*a) is True)
self.assertTrue((a < 2*a) is True)
self.assertTrue((a <= 2*a) is True)
self.assertTrue((a > 2*a) is False)
self.assertTrue((a >= 2*a) is False)
self.assertTrue((a == al) is False)
self.assertTrue((a != al) is True)
self.assertTrue((a < al) is False)
self.assertTrue((a <= al) is False)
self.assertTrue((a > al) is True)
self.assertTrue((a >= al) is True)
self.assertTrue((a == ab) is False)
self.assertTrue((a != ab) is True)
self.assertTrue((a < ab) is True)
self.assertTrue((a <= ab) is True)
self.assertTrue((a > ab) is False)
self.assertTrue((a >= ab) is False)
self.assertIs(a == 2*a, False)
self.assertIs(a != 2*a, True)
self.assertIs(a < 2*a, True)
self.assertIs(a <= 2*a, True)
self.assertIs(a > 2*a, False)
self.assertIs(a >= 2*a, False)
self.assertIs(a == al, False)
self.assertIs(a != al, True)
self.assertIs(a < al, False)
self.assertIs(a <= al, False)
self.assertIs(a > al, True)
self.assertIs(a >= al, True)
self.assertIs(a == ab, False)
self.assertIs(a != ab, True)
self.assertIs(a < ab, True)
self.assertIs(a <= ab, True)
self.assertIs(a > ab, False)
self.assertIs(a >= ab, False)
def test_add(self):
a = array.array(self.typecode, self.example) \
......@@ -493,7 +493,7 @@ class BaseTest:
a = array.array(self.typecode, self.example[::-1])
b = a
a += array.array(self.typecode, 2*self.example)
self.assertTrue(a is b)
self.assertIs(a, b)
self.assertEqual(
a,
array.array(self.typecode, self.example[::-1]+2*self.example)
......@@ -548,22 +548,22 @@ class BaseTest:
b = a
a *= 5
self.assertTrue(a is b)
self.assertIs(a, b)
self.assertEqual(
a,
array.array(self.typecode, 5*self.example)
)
a *= 0
self.assertTrue(a is b)
self.assertIs(a, b)
self.assertEqual(a, array.array(self.typecode))
a *= 1000
self.assertTrue(a is b)
self.assertIs(a, b)
self.assertEqual(a, array.array(self.typecode))
a *= -1
self.assertTrue(a is b)
self.assertIs(a, b)
self.assertEqual(a, array.array(self.typecode))
a = array.array(self.typecode, self.example)
......
......@@ -45,7 +45,7 @@ class LabeledScaleTest(unittest.TestCase):
# it tries calling instance attributes not yet defined.
ttk.LabeledScale(variable=myvar)
if hasattr(sys, 'last_type'):
self.assertFalse(sys.last_type == tkinter.TclError)
self.assertNotEqual(sys.last_type, tkinter.TclError)
def test_initialization(self):
......@@ -120,14 +120,14 @@ class LabeledScaleTest(unittest.TestCase):
# at the same time this shouldn't affect test outcome
lscale.update()
curr_xcoord = lscale.scale.coords()[0]
self.assertTrue(prev_xcoord != curr_xcoord)
self.assertNotEqual(prev_xcoord, curr_xcoord)
# the label widget should have been repositioned too
linfo_2 = lscale.label.place_info()
self.assertEqual(lscale.label['text'], 0)
self.assertEqual(curr_xcoord, int(linfo_2['x']))
# change the range back
lscale.scale.configure(from_=0, to=10)
self.assertTrue(prev_xcoord != curr_xcoord)
self.assertNotEqual(prev_xcoord, curr_xcoord)
self.assertEqual(prev_xcoord, int(linfo_1['x']))
lscale.destroy()
......@@ -146,7 +146,7 @@ class LabeledScaleTest(unittest.TestCase):
# at the same time this shouldn't affect test outcome
x.update()
self.assertEqual(x.label['text'], newval)
self.assertTrue(x.scale.coords()[0] > curr_xcoord)
self.assertGreater(x.scale.coords()[0], curr_xcoord)
self.assertEqual(x.scale.coords()[0],
int(x.label.place_info()['x']))
......@@ -238,7 +238,7 @@ class OptionMenuTest(unittest.TestCase):
if last == curr:
# no more menu entries
break
self.assertFalse(curr == default)
self.assertNotEqual(curr, default)
i += 1
self.assertEqual(i, len(items))
......
......@@ -18,7 +18,7 @@ class StyleTest(unittest.TestCase):
style.configure('TButton', background='yellow')
self.assertEqual(style.configure('TButton', 'background'),
'yellow')
self.assertTrue(isinstance(style.configure('TButton'), dict))
self.assertIsInstance(style.configure('TButton'), dict)
def test_map(self):
......@@ -26,7 +26,7 @@ class StyleTest(unittest.TestCase):
style.map('TButton', background=[('active', 'background', 'blue')])
self.assertEqual(style.map('TButton', 'background'),
[('active', 'background', 'blue')])
self.assertTrue(isinstance(style.map('TButton'), dict))
self.assertIsInstance(style.map('TButton'), dict)
def test_lookup(self):
......@@ -57,7 +57,7 @@ class StyleTest(unittest.TestCase):
self.assertEqual(style.layout('Treeview'), tv_style)
# should return a list
self.assertTrue(isinstance(style.layout('TButton'), list))
self.assertIsInstance(style.layout('TButton'), list)
# correct layout, but "option" doesn't exist as option
self.assertRaises(tkinter.TclError, style.layout, 'Treeview',
......
......@@ -273,7 +273,7 @@ class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
cbtn['command'] = ''
res = cbtn.invoke()
self.assertFalse(str(res))
self.assertFalse(len(success) > 1)
self.assertLessEqual(len(success), 1)
self.assertEqual(cbtn['offvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))
......@@ -454,7 +454,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
def test_bbox(self):
self.assertEqual(len(self.entry.bbox(0)), 4)
for item in self.entry.bbox(0):
self.assertTrue(isinstance(item, int))
self.assertIsInstance(item, int)
self.assertRaises(tkinter.TclError, self.entry.bbox, 'noindex')
self.assertRaises(tkinter.TclError, self.entry.bbox, None)
......@@ -652,7 +652,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
child = ttk.Label()
self.paned.add(child)
self.assertTrue(isinstance(self.paned.pane(0), dict))
self.assertIsInstance(self.paned.pane(0), dict)
self.assertEqual(self.paned.pane(0, weight=None), 0)
# newer form for querying a single option
self.assertEqual(self.paned.pane(0, 'weight'), 0)
......@@ -679,8 +679,8 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
curr_pos = self.paned.sashpos(0)
self.paned.sashpos(0, 1000)
self.assertTrue(curr_pos != self.paned.sashpos(0))
self.assertTrue(isinstance(self.paned.sashpos(0), int))
self.assertNotEqual(curr_pos, self.paned.sashpos(0))
self.assertIsInstance(self.paned.sashpos(0), int)
@add_standard_options(StandardTtkOptionsTests)
......@@ -720,7 +720,7 @@ class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
cbtn2['command'] = ''
res = cbtn2.invoke()
self.assertEqual(str(res), '')
self.assertFalse(len(success) > 1)
self.assertLessEqual(len(success), 1)
self.assertEqual(cbtn2['value'], myvar.get())
self.assertEqual(myvar.get(),
cbtn.tk.globalgetvar(cbtn['variable']))
......@@ -982,7 +982,7 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
self.nb.add(self.child2)
self.assertEqual(self.nb.tabs(), tabs)
self.assertEqual(self.nb.index(self.child2), child2_index)
self.assertTrue(str(self.child2) == self.nb.tabs()[child2_index])
self.assertEqual(str(self.child2), self.nb.tabs()[child2_index])
# but the tab next to it (not hidden) is the one selected now
self.assertEqual(self.nb.index('current'), curr + 1)
......@@ -995,19 +995,19 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
tabs = self.nb.tabs()
child1_index = self.nb.index(self.child1)
self.nb.forget(self.child1)
self.assertFalse(str(self.child1) in self.nb.tabs())
self.assertNotIn(str(self.child1), self.nb.tabs())
self.assertEqual(len(tabs) - 1, len(self.nb.tabs()))
self.nb.add(self.child1)
self.assertEqual(self.nb.index(self.child1), 1)
self.assertFalse(child1_index == self.nb.index(self.child1))
self.assertNotEqual(child1_index, self.nb.index(self.child1))
def test_index(self):
self.assertRaises(tkinter.TclError, self.nb.index, -1)
self.assertRaises(tkinter.TclError, self.nb.index, None)
self.assertTrue(isinstance(self.nb.index('end'), int))
self.assertIsInstance(self.nb.index('end'), int)
self.assertEqual(self.nb.index(self.child1), 0)
self.assertEqual(self.nb.index(self.child2), 1)
self.assertEqual(self.nb.index('end'), 2)
......@@ -1071,7 +1071,7 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
self.assertRaises(tkinter.TclError, self.nb.tab, None)
self.assertTrue(isinstance(self.nb.tab(self.child1), dict))
self.assertIsInstance(self.nb.tab(self.child1), dict)
self.assertEqual(self.nb.tab(self.child1, text=None), 'a')
# newer form for querying a single option
self.assertEqual(self.nb.tab(self.child1, 'text'), 'a')
......@@ -1192,7 +1192,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
bbox = self.tv.bbox(children[0])
self.assertEqual(len(bbox), 4)
self.assertTrue(isinstance(bbox, tuple))
self.assertIsInstance(bbox, tuple)
for item in bbox:
if not isinstance(item, int):
self.fail("Invalid bounding box: %s" % bbox)
......@@ -1215,7 +1215,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self.assertEqual(self.tv.get_children(), ())
item_id = self.tv.insert('', 'end')
self.assertTrue(isinstance(self.tv.get_children(), tuple))
self.assertIsInstance(self.tv.get_children(), tuple)
self.assertEqual(self.tv.get_children()[0], item_id)
# add item_id and child3 as children of child2
......@@ -1240,9 +1240,9 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
def test_column(self):
# return a dict with all options/values
self.assertTrue(isinstance(self.tv.column('#0'), dict))
self.assertIsInstance(self.tv.column('#0'), dict)
# return a single value of the given option
self.assertTrue(isinstance(self.tv.column('#0', width=None), int))
self.assertIsInstance(self.tv.column('#0', width=None), int)
# set a new value for an option
self.tv.column('#0', width=10)
# testing new way to get option value
......@@ -1355,7 +1355,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
def test_heading(self):
# check a dict is returned
self.assertTrue(isinstance(self.tv.heading('#0'), dict))
self.assertIsInstance(self.tv.heading('#0'), dict)
# check a value is returned
self.tv.heading('#0', text='hi')
......@@ -1466,7 +1466,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self.tv.item(item, values=list(self.tv.item(item, values=None)))
self.assertEqual(self.tv.item(item, values=None), (value, ))
self.assertTrue(isinstance(self.tv.item(item), dict))
self.assertIsInstance(self.tv.item(item), dict)
# erase item values
self.tv.item(item, values='')
......@@ -1567,7 +1567,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
'blue')
self.assertEqual(str(self.tv.tag_configure('test', foreground=None)),
'blue')
self.assertTrue(isinstance(self.tv.tag_configure('test'), dict))
self.assertIsInstance(self.tv.tag_configure('test'), dict)
@add_standard_options(StandardTtkOptionsTests)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment