404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.143.236.11: ~ $
# Copyright 2010, 2011  Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import io as StringIO
import unittest

import ttystatus


if 'unicode' in __builtins__:
    make_text = __builtins__['unicode']
else:
    make_text = str


class DummyMessager(object):

    def __init__(self):
        self.written = StringIO.StringIO()
        self.enabled = True
        self.fake_width = 80

    def get_max_line_length(self):
        return self.fake_width

    def clear(self):
        pass

    def time_to_write(self):
        return True

    def write(self, string, force=False):
        self.written.write(make_text(string))

    def notify(self, string, f, force=False):
        pass

    def finish(self):
        pass

    def enable(self):
        self.enabled = True

    def disable(self):
        self.enabled = False


class TerminalStatusTests(unittest.TestCase):

    def setUp(self):
        self.ts = ttystatus.TerminalStatus(messager=DummyMessager())

    def test_has_no_widgets(self):
        self.assertEqual(self.ts.widgets, [])

    def test_adds_widget(self):
        w = ttystatus.Literal('foo')
        self.ts.add(w)
        self.assertEqual(self.ts.widgets, [w])

    def test_adds_widgets_from_format_string(self):
        self.ts.format('hello, %String(name)')
        self.assertEqual(len(self.ts.widgets), 2)
        self.assertEqual(type(self.ts.widgets[0]), ttystatus.Literal)
        self.assertEqual(type(self.ts.widgets[1]), ttystatus.String)

    def test_removes_all_widgets(self):
        self.ts.add(ttystatus.Literal('foo'))
        self.ts.clear()
        self.assertEqual(self.ts.widgets, [])

    def test_returns_empty_string_for_unknown_value(self):
        self.assertEqual(self.ts['foo'], '')

    def test_sets_value(self):
        self.ts['foo'] = 'bar'
        self.assertEqual(self.ts['foo'], 'bar')

    def test_gets_value(self):
        self.ts['foo'] = 'bar'
        self.assertEqual(self.ts.get('foo'), 'bar')

    def test_gets_default_value_for_nonexistent_key(self):
        self.assertEqual(self.ts.get('foo', 'bar'), 'bar')

    def test_gets_None_for_nonexistent_key_without_default_value(self):
        self.assertEqual(self.ts.get('foo'), None)

    def test_updates_widgets_when_value_is_set(self):
        w = ttystatus.String('foo')
        self.ts.add(w)
        self.assertEqual(w.render(0), '')
        self.ts['foo'] = 'bar'
        self.assertEqual(w.render(0), 'bar')

    def test_increases_value(self):
        self.ts['foo'] = 10
        self.assertEqual(self.ts['foo'], 10)
        self.ts.increase('foo', 10)
        self.assertEqual(self.ts['foo'], 20)

    def test_has_notify_method(self):
        self.assertEqual(self.ts.notify('foo'), None)

    def test_has_error_method(self):
        self.assertEqual(self.ts.error('foo'), None)

    def test_has_finish_method(self):
        self.assertEqual(self.ts.finish(), None)

    def test_flushes(self):
        self.ts._m.time_to_write = lambda: False
        self.ts.format('%String(foo)')
        self.ts['foo'] = 'foo'
        self.assertEqual(self.ts._m.written.getvalue(), '')
        self.ts.flush()
        self.assertEqual(self.ts._m.written.getvalue(), 'foo')

    def test_disable_calls_messager_disable(self):
        self.ts.disable()
        self.assertFalse(self.ts._m.enabled)

    def test_enable_calls_messager_enable(self):
        self.ts.disable()
        self.ts.enable()
        self.assertTrue(self.ts._m.enabled)

    def test_counts_correctly_even_without_rendering(self):
        w = ttystatus.Counter('value')
        n = 42
        self.ts.add(w)
        for i in range(n):
            self.ts['value'] = i
        self.assertEqual(w.render(0), str(n))

    def test_renders_everything_when_there_is_space(self):
        w1 = ttystatus.Literal('foo')
        w2 = ttystatus.ProgressBar('done', 'total')
        self.ts.add(w1)
        self.ts.add(w2)
        text = self.ts._render()
        self.assertEqual(len(text), self.ts._m.get_max_line_length())

    def test_renders_from_beginning_if_there_is_not_enough_space(self):
        w1 = ttystatus.Literal('foo')
        w2 = ttystatus.Literal('bar')
        self.ts.add(w1)
        self.ts.add(w2)
        self.ts._m.fake_width = 4
        text = self.ts._render()
        self.assertEqual(text, 'foob')

    def test_renders_variable_size_width_according_to_space_keep_static(self):
        w1 = ttystatus.Literal('foo')
        w2 = ttystatus.ProgressBar('done', 'total')
        w3 = ttystatus.Literal('bar')
        self.ts.add(w1)
        self.ts.add(w2)
        self.ts.add(w3)
        self.ts._m.fake_width = 9
        text = self.ts._render()
        self.assertEqual(text, 'foo---bar')

Filemanager

Name Type Size Permission Actions
__init__.py File 1.29 KB 0644
__init__.pyc File 1.25 KB 0644
area.py File 3.41 KB 0644
area.pyc File 3.9 KB 0644
bytesize.py File 1.39 KB 0644
bytesize.pyc File 1.37 KB 0644
bytesize_tests.py File 1.95 KB 0644
bytesize_tests.pyc File 3.11 KB 0644
bytespeed.py File 2.26 KB 0644
bytespeed.pyc File 2.17 KB 0644
bytespeed_tests.py File 2.54 KB 0644
bytespeed_tests.pyc File 4.77 KB 0644
counter.py File 1.1 KB 0644
counter.pyc File 1.13 KB 0644
counter_tests.py File 1.42 KB 0644
counter_tests.pyc File 1.97 KB 0644
elapsed.py File 1.35 KB 0644
elapsed.pyc File 1.43 KB 0644
elapsed_tests.py File 1.38 KB 0644
elapsed_tests.pyc File 2.14 KB 0644
fmt.py File 2.15 KB 0644
fmt.pyc File 1.74 KB 0644
fmt_tests.py File 2.39 KB 0644
fmt_tests.pyc File 2.78 KB 0644
index.py File 1.25 KB 0644
index.pyc File 1.24 KB 0644
index_tests.py File 1.27 KB 0644
index_tests.pyc File 1.7 KB 0644
integer.py File 1.06 KB 0644
integer.pyc File 1.12 KB 0644
integer_tests.py File 1.22 KB 0644
integer_tests.pyc File 1.64 KB 0644
literal.py File 877 B 0644
literal.pyc File 791 B 0644
literal_tests.py File 984 B 0644
literal_tests.pyc File 1.09 KB 0644
messager.py File 4.52 KB 0644
messager.pyc File 4.61 KB 0644
pathname.py File 1.07 KB 0644
pathname.pyc File 1.12 KB 0644
pathname_tests.py File 1.36 KB 0644
pathname_tests.pyc File 1.92 KB 0644
percent.py File 1.4 KB 0644
percent.pyc File 1.35 KB 0644
percent_tests.py File 1.42 KB 0644
percent_tests.pyc File 2 KB 0644
progressbar.py File 1.46 KB 0644
progressbar.pyc File 1.41 KB 0644
progressbar_tests.py File 2.33 KB 0644
progressbar_tests.pyc File 3.77 KB 0644
remtime.py File 1.89 KB 0644
remtime.pyc File 1.81 KB 0644
remtime_tests.py File 2.08 KB 0644
remtime_tests.pyc File 3.26 KB 0644
speed.py File 1.94 KB 0644
speed.pyc File 1.83 KB 0644
speed_tests.py File 1001 B 0644
speed_tests.pyc File 1.1 KB 0644
status.py File 6.15 KB 0644
status.pyc File 8.2 KB 0644
status_tests.py File 5.18 KB 0644
status_tests.pyc File 8.97 KB 0644
string.py File 998 B 0644
string.pyc File 1.02 KB 0644
string_tests.py File 1.2 KB 0644
string_tests.pyc File 1.61 KB 0644
tty.py File 2.87 KB 0644
tty.pyc File 3.33 KB 0644
version.py File 48 B 0644
version.pyc File 225 B 0644
widget.py File 2.22 KB 0644
widget.pyc File 2.13 KB 0644