Пример #1
0
 def test_write_bytes_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(bytes('my_history',
                              sys.getfilesystemencoding()),
                        raise_exc=True)
     self.assertTrue(isfile('my_history'))
Пример #2
0
 def setUp(self):
     reset()
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     history.append('pebbles')
Пример #3
0
 def test_replace(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[2] = 'dino'
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[0] = 'hopper'
     self.assertEqual(history[0], 'hopper')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[-1] = 'bedrock'
     self.assertEqual(history[0], 'hopper')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bedrock')
Пример #4
0
 def test_read_tilde_expanded(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(self.histfile, raise_exc=True)
     history.clear()
     history.read_file('~/.history', raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #5
0
 def test_read_default_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(self.histfile, raise_exc=True)
     history.clear()
     history.read_file(raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #6
0
 def test_replace(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[2] = 'dino'
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[0] = 'hopper'
     self.assertEqual(history[0], 'hopper')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     history[-1] = 'bedrock'
     self.assertEqual(history[0], 'hopper')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'dino')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bedrock')
Пример #7
0
 def test_read_tilde_expanded(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(self.histfile, raise_exc=True)
     history.clear()
     history.read_file('~/.history', raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #8
0
 def test_read_bytes_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(bytes('my_history', sys.getfilesystemencoding()), raise_exc=True)
     history.clear()
     history.read_file(bytes('my_history', sys.getfilesystemencoding()), raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #9
0
 def test_read_abspath(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.read_file(abspath('my_history'), raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #10
0
 def setUp(self):
     reset()
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     history.append('pebbles')
Пример #11
0
 def test_read_abspath(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.read_file(abspath('my_history'), raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #12
0
 def test_read_None_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(self.histfile, raise_exc=True)
     history.clear()
     history.read_file(None, raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #13
0
 def test__reversed__items(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual([x for x in reversed(history)], ['bammbamm', 'pebbles', 'betty', 'barney', 'wilma'])
     history.append('dino')
     self.assertEqual([x for x in reversed(history)], ['dino', 'bammbamm', 'pebbles', 'betty', 'barney'])
     history[0] = 'hopper'
     self.assertEqual([x for x in reversed(history)], ['dino', 'bammbamm', 'pebbles', 'betty', 'hopper'])
Пример #14
0
 def test__iter__items(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual([x for x in history], ['wilma', 'barney', 'betty', 'pebbles', 'bammbamm'])
     history.append('dino')
     self.assertEqual([x for x in history], ['barney', 'betty', 'pebbles', 'bammbamm', 'dino'])
     history[0] = 'hopper'
     self.assertEqual([x for x in history], ['hopper', 'betty', 'pebbles', 'bammbamm', 'dino'])
Пример #15
0
 def test_append_relative(self):
     history.write_file('my_history', raise_exc=True)
     history.append('fred')
     history.append('wilma')
     history.append_file(2, 'my_history')
     history.clear()
     history.read_file('my_history', raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #16
0
 def test_read_bytes_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(bytes('my_history',
                              sys.getfilesystemencoding()),
                        raise_exc=True)
     history.clear()
     history.read_file(bytes('my_history', sys.getfilesystemencoding()),
                       raise_exc=True)
     self.assertEqual(len(history), 2)
Пример #17
0
 def test_unstifled(self):
     history.max_entries = -1
     # Extend history beyond 5 entries
     history.append('bammbamm')
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'wilma')
     self.assertEqual(history[2], 'barney')
     self.assertEqual(history[3], 'betty')
     self.assertEqual(history[4], 'pebbles')
     self.assertEqual(history[5], 'bammbamm')
     self.assertEqual(len(history), 6)
Пример #18
0
 def test__iter__items(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual([x for x in history],
                      ['wilma', 'barney', 'betty', 'pebbles', 'bammbamm'])
     history.append('dino')
     self.assertEqual([x for x in history],
                      ['barney', 'betty', 'pebbles', 'bammbamm', 'dino'])
     history[0] = 'hopper'
     self.assertEqual([x for x in history],
                      ['hopper', 'betty', 'pebbles', 'bammbamm', 'dino'])
Пример #19
0
 def test_unstifled(self):
     history.max_entries = -1
     # Extend history beyond 5 entries
     history.append('bammbamm')
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'wilma')
     self.assertEqual(history[2], 'barney')
     self.assertEqual(history[3], 'betty')
     self.assertEqual(history[4], 'pebbles')
     self.assertEqual(history[5], 'bammbamm')
     self.assertEqual(len(history), 6)
Пример #20
0
 def test__reversed__items(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual([x for x in reversed(history)],
                      ['bammbamm', 'pebbles', 'betty', 'barney', 'wilma'])
     history.append('dino')
     self.assertEqual([x for x in reversed(history)],
                      ['dino', 'bammbamm', 'pebbles', 'betty', 'barney'])
     history[0] = 'hopper'
     self.assertEqual([x for x in reversed(history)],
                      ['dino', 'bammbamm', 'pebbles', 'betty', 'hopper'])
Пример #21
0
 def test_iterate(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual([x for x in reversed(history)],
                      ['betty', 'barney', 'wilma', 'fred'])
Пример #22
0
 def test_stifle_truncates_existing(self):
     history.max_entries = -1
     # Extend history beyond 5 entries
     history.append('bammbamm')
     history.append('dino')
     self.assertEqual(len(history), 7)
     # Now stifle
     history.max_entries = 5
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(history[4], 'dino')
     self.assertEqual(len(history), 5)
Пример #23
0
 def test_stifle_truncates_existing(self):
     history.max_entries = -1
     # Extend history beyond 5 entries
     history.append('bammbamm')
     history.append('dino')
     self.assertEqual(len(history), 7)
     # Now stifle
     history.max_entries = 5
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(history[4], 'dino')
     self.assertEqual(len(history), 5)
Пример #24
0
 def test_write_file_replaces_file(self):
     history.append('fred')
     history.append('wilma')
     history.append('pebbles')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.append('barney')
     history.append('betty')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.read_file('my_history', raise_exc=True)
     self.assertEqual(len(history), 2)
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
Пример #25
0
 def test__iter__items(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual([x for x in history], ['fred', 'wilma', 'barney', 'betty'])
Пример #26
0
 def test_iterate(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual([x for x in history],
                      ['fred', 'wilma', 'barney', 'betty'])
Пример #27
0
 def test__reversed__items(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual([x for x in reversed(history)], ['betty', 'barney', 'wilma', 'fred'])
Пример #28
0
 def test_set_slice(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertRaises(TypeError, history.__setitem__, slice(2, -1),
                       ['dino'])
Пример #29
0
 def test__iter__items(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual([x for x in history],
                      ['fred', 'wilma', 'barney', 'betty'])
Пример #30
0
 def test_reversed_iterator(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertRaises(TypeError, reversed, reversed(history))
     list = ['a', 'b', 'c', 'd']
     self.assertRaises(TypeError, reversed, reversed(list))
Пример #31
0
 def test_iterate_exhausted(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     i = reversed(history)
     self.assertEqual([x for x in i], ['betty', 'barney', 'wilma', 'fred'])
     self.assertRaises(StopIteration, i.next)
Пример #32
0
 def test_out_of_range_pos(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertRaises(IndexError, history.__getitem__, 4)
     self.assertRaises(IndexError, history.__getitem__, -5)
Пример #33
0
 def test_reversed_iterator(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertRaises(TypeError, reversed, reversed(history))
     list = ['a', 'b', 'c', 'd']
     self.assertRaises(TypeError, reversed, reversed(list))
Пример #34
0
 def test_iterate_iterator(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual([x for x in iter(reversed(history))], ['betty', 'barney', 'wilma', 'fred'])
     list = ['a', 'b', 'c', 'd']
     self.assertEqual([x for x in iter(reversed(list))], ['d', 'c', 'b', 'a'])
Пример #35
0
 def test_out_of_range_pos(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertRaises(IndexError, history.__getitem__, 4)
     self.assertRaises(IndexError, history.__getitem__, -5)
Пример #36
0
 def test_iterate_exhausted(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     i = reversed(history)
     self.assertEqual([x for x in i], ['betty', 'barney', 'wilma', 'fred'])
     self.assertRaises(StopIteration, next, i)
Пример #37
0
 def test_length_hint(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     i = reversed(history)
     self.assertEqual(i.__length_hint__(), len(history))
     for n, x in enumerate(i):
         self.assertEqual(i.__length_hint__(), len(history) - n - 1)
Пример #38
0
 def test_length_hint(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     i = reversed(history)
     self.assertEqual(i.__length_hint__(), len(history))
     for n, x in enumerate(i):
         self.assertEqual(i.__length_hint__(), len(history)-n-1)
Пример #39
0
 def test_iterate_iterator(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual([x for x in iter(iter(history))],
                      ['fred', 'wilma', 'barney', 'betty'])
     list = ['a', 'b', 'c', 'd']
     self.assertEqual([x for x in iter(iter(list))], ['a', 'b', 'c', 'd'])
Пример #40
0
 def test_negative_pos(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual(history[-4], 'fred')
     self.assertEqual(history[-3], 'wilma')
     self.assertEqual(history[-2], 'barney')
     self.assertEqual(history[-1], 'betty')
Пример #41
0
 def test__getitem__(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'wilma')
     self.assertEqual(history[2], 'barney')
     self.assertEqual(history[3], 'betty')
Пример #42
0
 def test_negative_pos(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual(history[-4], 'fred')
     self.assertEqual(history[-3], 'wilma')
     self.assertEqual(history[-2], 'barney')
     self.assertEqual(history[-1], 'betty')
Пример #43
0
 def test__getitem__(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'wilma')
     self.assertEqual(history[2], 'barney')
     self.assertEqual(history[3], 'betty')
Пример #44
0
 def test_stifled(self):
     history.max_entries = 5
     # Extend history beyond 5 entries
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     self.assertEqual(len(history), 5)
     # Add one more
     history.append('dino')
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(history[4], 'dino')
     self.assertEqual(len(history), 5)
Пример #45
0
 def test_stifled(self):
     history.max_entries = 5
     # Extend history beyond 5 entries
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     self.assertEqual(len(history), 5)
     # Add one more
     history.append('dino')
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(history[4], 'dino')
     self.assertEqual(len(history), 5)
Пример #46
0
 def test_write_file_replaces_file(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.append('barney')
     history.append('betty')
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.read_file('my_history', raise_exc=True)
     self.assertEqual(len(history), 2)
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
Пример #47
0
 def test__delitem__(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     del history[1]
     self.assertEqual(len(history), 3)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     del history[-2]
     self.assertEqual(len(history), 2)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'betty')
Пример #48
0
 def test_remove(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     del history[2]
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(len(history), 4)
     del history[0]
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(history[2], 'bammbamm')
     self.assertEqual(len(history), 3)
     del history[-1]
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(len(history), 2)
Пример #49
0
 def test_remove(self):
     history.max_entries = 5
     history.append('bammbamm')
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'betty')
     self.assertEqual(history[3], 'pebbles')
     self.assertEqual(history[4], 'bammbamm')
     del history[2]
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'barney')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(len(history), 4)
     del history[0]
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(history[2], 'bammbamm')
     self.assertEqual(len(history), 3)
     del history[-1]
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(len(history), 2)
Пример #50
0
 def test__setitem__(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     self.assertEqual(len(history), 4)
     history[1] = 'pebbles'
     self.assertEqual(len(history), 4)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(history[2], 'barney')
     self.assertEqual(history[3], 'betty')
     history[-2] = 'bammbamm'
     self.assertEqual(len(history), 4)
     self.assertEqual(history[0], 'fred')
     self.assertEqual(history[1], 'pebbles')
     self.assertEqual(history[2], 'bammbamm')
     self.assertEqual(history[3], 'betty')
Пример #51
0
 def test_write_file_truncates_file(self):
     history.append('fred')
     history.append('wilma')
     history.append('pebbles')
     history.max_file = 2
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.read_file('my_history', raise_exc=True)
     self.assertEqual(len(history), 2)
     self.assertEqual(history[0], 'wilma')
     self.assertEqual(history[1], 'pebbles')
Пример #52
0
 def test_write_abspath(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(abspath('my_history'), raise_exc=True)
     self.assertTrue(isfile(abspath('my_history')))
     self.assertTrue(isfile('my_history'))
Пример #53
0
 def test_write_abspath(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(abspath('my_history'), raise_exc=True)
     self.assertTrue(isfile(abspath('my_history')))
     self.assertTrue(isfile('my_history'))
Пример #54
0
 def test_write_None_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(None, raise_exc=True)
     self.assertTrue(isfile(self.histfile))
Пример #55
0
 def test_write_relative(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('my_history', raise_exc=True)
     self.assertTrue(isfile('my_history'))
Пример #56
0
 def test_write_file_stifled(self):
     history.append('fred')
     history.append('wilma')
     history.append('barney')
     history.append('betty')
     history.append('pebbles')
     history.append('bammbamm')
     history.append('dino')
     self.assertEqual(len(history), 7)
     history.max_entries = 5
     history.write_file('my_history', raise_exc=True)
     history.clear()
     history.max_entries = -1
     history.read_file('my_history', raise_exc=True)
     self.assertEqual(history[0], 'barney')
     self.assertEqual(history[1], 'betty')
     self.assertEqual(history[2], 'pebbles')
     self.assertEqual(history[3], 'bammbamm')
     self.assertEqual(history[4], 'dino')
     self.assertEqual(len(history), 5)
Пример #57
0
 def test_write_tilde_expanded(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('~/.history', raise_exc=True)
     self.assertTrue(isfile(self.histfile))
Пример #58
0
 def test_write_None_name(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(None, raise_exc=True)
     self.assertTrue(isfile(self.histfile))
Пример #59
0
 def test_read_empty_string(self):
     history.append('fred')
     history.append('wilma')
     history.write_file(self.histfile, raise_exc=True)
     history.clear()
     self.assertRaises(IOError, history.read_file, '', raise_exc=True)
Пример #60
0
 def test_write_relative(self):
     history.append('fred')
     history.append('wilma')
     history.write_file('my_history', raise_exc=True)
     self.assertTrue(isfile('my_history'))