diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-06-05 13:11:59 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-06-05 13:11:59 +1200 |
commit | 1afa05cd11db2c67e56dedc591a760140e87c14d (patch) | |
tree | 1169f012dc0660d56ccf9b398bfdf886f417397c | |
download | python-ttystatus-1afa05cd11db2c67e56dedc591a760140e87c14d.tar.gz |
Add initial test and code to implement it.
-rw-r--r-- | ttystatus/__init__.py | 17 | ||||
-rw-r--r-- | ttystatus/messager.py | 28 | ||||
-rw-r--r-- | ttystatus/messager_tests.py | 41 |
3 files changed, 86 insertions, 0 deletions
diff --git a/ttystatus/__init__.py b/ttystatus/__init__.py new file mode 100644 index 0000000..db97c0b --- /dev/null +++ b/ttystatus/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2010 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/>. + + +from messager import Messager diff --git a/ttystatus/messager.py b/ttystatus/messager.py new file mode 100644 index 0000000..c961267 --- /dev/null +++ b/ttystatus/messager.py @@ -0,0 +1,28 @@ +# Copyright 2010 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 sys + + +class Messager(object): + + '''Write messages to the terminal.''' + + def __init__(self, output=None): + self.output = output or sys.stderr + + def raw_write(self, string): + self.output.write(string) diff --git a/ttystatus/messager_tests.py b/ttystatus/messager_tests.py new file mode 100644 index 0000000..000f182 --- /dev/null +++ b/ttystatus/messager_tests.py @@ -0,0 +1,41 @@ +# Copyright 2010 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 StringIO +import unittest + +import ttystatus + + +class DummyTerminal(StringIO.StringIO): + + def isatty(self): + return True + + +class MessagerTests(unittest.TestCase): + + def setUp(self): + self.output = DummyTerminal() + self.messager = ttystatus.Messager(output=self.output) + + def test_sets_output(self): + self.assertEqual(self.messager.output, self.output) + + def test_writes_nothing_if_output_is_not_a_terminal(self): + self.messager.output = StringIO.StringIO() + self.messager.raw_write('foo') + self.assertEqual(self.output.getvalue(), '') |