Revision 5e383dd4 kamaki/cli/test.py

b/kamaki/cli/test.py
37 37
from mock import patch, call
38 38
from itertools import product
39 39

  
40
from kamaki.cli.command_tree.test import Command, CommandTree
41
from kamaki.cli.config.test import Config
42
from kamaki.cli.argument.test import (
43
    Argument, ConfigArgument, RuntimeConfigArgument, FlagArgument,
44
    ValueArgument, IntArgument, DateArgument, VersionArgument,
45
    RepeatableArgument, KeyValueArgument, ProgressBarArgument,
46
    ArgumentParseManager)
47
from kamaki.cli.utils.test import UtilsMethods
48

  
49 40

  
50 41
class History(TestCase):
51 42

  
......
88 79
        history = self.HCLASS(self.file.name)
89 80
        history.empty()
90 81
        self.file.seek(0)
91
        self.assertEqual(self.file.read(), '')
82
        self.assertEqual(self.file.read(), '0\n')
92 83

  
93 84
    def test_retrieve(self):
94 85
        sample_history = (
......
107 98
        for i in (0, len(sample_history) + 1, - len(sample_history) - 1):
108 99
            self.assertEqual(history.retrieve(i), None)
109 100
        for i in range(1, len(sample_history)):
110
            self.assertEqual(history.retrieve(i), sample_history[i - 1])
101
            self.assertEqual(history.retrieve(i), sample_history[i])
111 102
            self.assertEqual(history.retrieve(- i), sample_history[- i])
112 103

  
104
    def test_limit(self):
105
        sample_history = (
106
            'kamaki history show\n',
107
            'kamaki file list\n',
108
            'kamaki file create /pithos/f1\n',
109
            'kamaki file info /pithos/f1\n',
110
            'last command is always excluded')
111
        sample_len = len(sample_history)
112
        self.file.write(''.join(sample_history))
113
        self.file.flush()
114
        history = self.HCLASS(self.file.name)
115

  
116
        for value, exp_e in (
117
                    (-2, ValueError),
118
                    ('non int', ValueError),
119
                    (None, TypeError)):
120
            try:
121
                history.limit = value
122
            except Exception as e:
123
                self.assertTrue(isinstance(e, exp_e))
124

  
125
        history.limit = 10
126
        self.assertEqual(history.limit, 10)
127
        self.file.seek(0)
128
        self.assertEqual(len(self.file.readlines()), sample_len)
129

  
130
        history.limit = sample_len - 1
131
        self.assertEqual(history.limit, sample_len - 1)
132
        self.file.seek(0)
133
        self.assertEqual(len(self.file.readlines()), sample_len)
134

  
113 135

  
114 136
class LoggerMethods(TestCase):
115 137

  

Also available in: Unified diff