|
@@ -33,27 +33,52 @@ def test_stats_basic(stats):
|
|
assert stats.usize == 20
|
|
assert stats.usize == 20
|
|
|
|
|
|
|
|
|
|
-@pytest.mark.parametrize(
|
|
|
|
- "item_path, update_size, expected_output",
|
|
|
|
- [
|
|
|
|
- ("", 0, "20 B O 20 B U 1 N "), # test unchanged 'stats' fixture
|
|
|
|
- ("foo", 10**3, "1.02 kB O 20 B U 1 N foo"), # test updated original size and set item path
|
|
|
|
- # test long item path which exceeds 80 characters
|
|
|
|
- ("foo" * 40, 10**3, "1.02 kB O 20 B U 1 N foofoofoofoofoofoofoofoofo...foofoofoofoofoofoofoofoofoofoo"),
|
|
|
|
- ],
|
|
|
|
-)
|
|
|
|
-def test_stats_progress(item_path, update_size, expected_output, stats, monkeypatch, columns=80):
|
|
|
|
|
|
+def test_stats_progress_tty(stats, monkeypatch, columns=80):
|
|
|
|
+ class TTYStringIO(StringIO):
|
|
|
|
+ def isatty(self):
|
|
|
|
+ return True
|
|
|
|
+
|
|
monkeypatch.setenv("COLUMNS", str(columns))
|
|
monkeypatch.setenv("COLUMNS", str(columns))
|
|
- out = StringIO()
|
|
|
|
- item = Item(path=item_path) if item_path else None
|
|
|
|
- s = expected_output
|
|
|
|
|
|
+ out = TTYStringIO()
|
|
|
|
+ stats.show_progress(stream=out)
|
|
|
|
+ s = "20 B O 20 B U 1 N "
|
|
|
|
+ buf = " " * (columns - len(s))
|
|
|
|
+ assert out.getvalue() == s + buf + "\r"
|
|
|
|
+
|
|
|
|
+ out = TTYStringIO()
|
|
|
|
+ stats.update(10**3, unique=False)
|
|
|
|
+ stats.show_progress(item=Item(path="foo"), final=False, stream=out)
|
|
|
|
+ s = "1.02 kB O 20 B U 1 N foo"
|
|
|
|
+ buf = " " * (columns - len(s))
|
|
|
|
+ assert out.getvalue() == s + buf + "\r"
|
|
|
|
|
|
- stats.update(update_size, unique=False)
|
|
|
|
- stats.show_progress(item=item, stream=out)
|
|
|
|
|
|
+ out = TTYStringIO()
|
|
|
|
+ stats.show_progress(item=Item(path="foo" * 40), final=False, stream=out)
|
|
|
|
+ s = "1.02 kB O 20 B U 1 N foofoofoofoofoofoofoofoofo...foofoofoofoofoofoofoofoofoofoo"
|
|
buf = " " * (columns - len(s))
|
|
buf = " " * (columns - len(s))
|
|
assert out.getvalue() == s + buf + "\r"
|
|
assert out.getvalue() == s + buf + "\r"
|
|
|
|
|
|
|
|
|
|
|
|
+def test_stats_progress_file(stats, monkeypatch):
|
|
|
|
+ out = StringIO()
|
|
|
|
+ stats.show_progress(stream=out)
|
|
|
|
+ s = "20 B O 20 B U 1 N "
|
|
|
|
+ assert out.getvalue() == s + "\n"
|
|
|
|
+
|
|
|
|
+ out = StringIO()
|
|
|
|
+ stats.update(10**3, unique=False)
|
|
|
|
+ path = "foo"
|
|
|
|
+ stats.show_progress(item=Item(path=path), final=False, stream=out)
|
|
|
|
+ s = f"1.02 kB O 20 B U 1 N {path}"
|
|
|
|
+ assert out.getvalue() == s + "\n"
|
|
|
|
+
|
|
|
|
+ out = StringIO()
|
|
|
|
+ path = "foo" * 40
|
|
|
|
+ stats.show_progress(item=Item(path=path), final=False, stream=out)
|
|
|
|
+ s = f"1.02 kB O 20 B U 1 N {path}"
|
|
|
|
+ assert out.getvalue() == s + "\n"
|
|
|
|
+
|
|
|
|
+
|
|
def test_stats_format(stats):
|
|
def test_stats_format(stats):
|
|
assert (
|
|
assert (
|
|
str(stats)
|
|
str(stats)
|