Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Jul 6, 2024
1 parent cc3e023 commit 60cba72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 4 additions & 10 deletions atpbar/stream/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ def __init__(self, queue: StreamQueue, fd: FD) -> None:
self.buffer = ''

def write(self, s: str) -> int:
# sys.__stdout__.write(repr(s))
# sys.__stdout__.write('\n')
if not isinstance(s, str):
# The same error message as `sys.stdout.write()`
raise TypeError(f'write() argument must be str, not {type(s).__name__}')

try:
endswith_n = s.endswith('\n')
except:
self.flush()
self.queue.put((s, self.fd))
return len(s)

if endswith_n:
if s.endswith('\n'):
self.buffer += s
self.flush()
return len(s)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from unittest.mock import sentinel

import pytest
from hypothesis import given, settings
from hypothesis import strategies as st

from atpbar.stream import OutputStream, Queue, StreamQueue
from tests.stream.st import st_text


def test_type_error() -> None:
stream = OutputStream(Queue(), sentinel.fd)
with pytest.raises(TypeError):
stream.write(123) # type: ignore


class StatefulTest:
def __init__(self, data: st.DataObject) -> None:
self.draw = data.draw
Expand Down

0 comments on commit 60cba72

Please sign in to comment.