Skip to content

Commit

Permalink
Add test for handling tqdm stream redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
8W9aG committed Nov 26, 2024
1 parent 7126313 commit 814e72a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
python_version: "3.11"
python_packages:
- "pillow==8.3.2"
- "tqdm==4.66.6"
predict: "predict.py:Predictor"
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
from cog import BasePredictor, File
import logging
import os
from PIL import Image
from cog import BasePredictor
import tqdm
import time


class Predictor(BasePredictor):
def setup(self):
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")
rootLogger = logging.getLogger()

fileHandler = logging.FileHandler("{0}/{1}.log".format(os.path.dirname(__file__), "mylog.log"))
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)

consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)

def predict(self) -> list[Image]:
logging.info("Do some logging.")
return []
def predict(self) -> str:
print("Starting Predict:")
for i in tqdm.tqdm(range(10), total=10):
time.sleep(i)
return "Hello World"
1 change: 0 additions & 1 deletion test-integration/test_integration/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def test_file_logging_stream_drain(tmpdir_factory):
cmd,
cwd=out_dir,
check=True,
capture_output=True,
text=True,
timeout=DEFAULT_TIMEOUT,
)

0 comments on commit 814e72a

Please sign in to comment.