OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 Dirk Pranke. All rights reserved. |
| 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at |
| 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. |
| 14 |
| 15 import unittest |
| 16 |
| 17 from typ.printer import Printer |
| 18 |
| 19 |
| 20 class TestPrinter(unittest.TestCase): |
| 21 |
| 22 def setUp(self): |
| 23 # 'Invalid name' pylint: disable=C0103 |
| 24 self.out = [] |
| 25 |
| 26 def print_(self, msg, end='\n'): |
| 27 self.out.append(msg + end) |
| 28 |
| 29 def test_basic(self): |
| 30 pr = Printer(self.print_, False, 80) |
| 31 pr.update('foo') |
| 32 pr.flush() |
| 33 self.assertEqual(self.out, ['foo', '\n']) |
| 34 |
| 35 def test_elide(self): |
| 36 pr = Printer(self.print_, False, 8) |
| 37 pr.update('hello world') |
| 38 pr.flush() |
| 39 self.assertEqual(self.out, ['h...d', '\n']) |
| 40 |
| 41 def test_overwrite(self): |
| 42 pr = Printer(self.print_, True, 80) |
| 43 pr.update('hello world') |
| 44 pr.update('goodbye world') |
| 45 pr.flush() |
| 46 self.assertEqual(self.out, |
| 47 ['hello world', |
| 48 '\r \r', |
| 49 'goodbye world', |
| 50 '\n']) |
| 51 |
| 52 def test_last_line_flushed_when_not_overwriting(self): |
| 53 pr = Printer(self.print_, False, 80) |
| 54 pr.update('foo\nbar') |
| 55 pr.update('baz') |
| 56 pr.flush() |
| 57 self.assertEqual(self.out, |
| 58 ['foo\nbar', |
| 59 '\n', |
| 60 'baz', |
| 61 '\n']) |
OLD | NEW |