Skip to content

Commit

Permalink
update test get envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleyDL committed May 2, 2024
1 parent e53ace3 commit fc3b59b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
48 changes: 0 additions & 48 deletions streamlit_img_label/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from PIL import Image




class ImageManager:
"""ImageManager Manage the image object.
Expand All @@ -28,17 +26,9 @@ def __init__(self, filename):
self._filename = filename
self._img = Image.open(filename)
self._rects = []
# self._load_rects()
self._resized_ratio_w = 1
self._resized_ratio_h = 1


# def _load_rects(self):
# rects_xml = read_xml(self._filename)
# if rects_xml:
# self._rects = rects_xml


def get_img(self):
"""get the image object
Expand All @@ -47,7 +37,6 @@ def get_img(self):
"""
return self._img


def get_rects(self):
"""get the rects
Expand All @@ -56,7 +45,6 @@ def get_rects(self):
"""
return self._rects


def resizing_img(self, max_height=700, max_width=700):
"""resizing the image by max_height and max_width.
Expand All @@ -82,7 +70,6 @@ def resizing_img(self, max_height=700, max_width=700):
self._resized_ratio_h = self._img.height / resized_img.height
return resized_img


def _resize_rect(self, rect):
resized_rect = {}
resized_rect["left"] = rect["left"] / self._resized_ratio_w
Expand All @@ -93,7 +80,6 @@ def _resize_rect(self, rect):
resized_rect["label"] = rect["label"]
return resized_rect


def get_resized_rects(self):
"""get resized the rects according to the resized image.
Expand All @@ -102,7 +88,6 @@ def get_resized_rects(self):
"""
return [self._resize_rect(rect) for rect in self._rects]


def _chop_box_img(self, rect):
rect["left"] = int(rect["left"] * self._resized_ratio_w)
rect["width"] = int(rect["width"] * self._resized_ratio_w)
Expand All @@ -126,7 +111,6 @@ def _chop_box_img(self, rect):
label = rect["label"]
return (Image.fromarray(prev_img), label)


def init_annotation(self, rects):
"""init annotation for current rects.
Expand All @@ -138,7 +122,6 @@ def init_annotation(self, rects):
self._current_rects = rects
return [self._chop_box_img(rect) for rect in self._current_rects]


def set_annotation(self, index, label):
"""set the label of the image.
Expand All @@ -149,8 +132,6 @@ def set_annotation(self, index, label):
self._current_rects[index]["label"] = label




class ArchiveImageManager:
"""ArchiveImageManager Manage the image object in bytes.
Expand All @@ -160,13 +141,11 @@ class ArchiveImageManager:

def __init__(self, img):
"""initiate module"""
# self._filename = filename
self._img = Image.open(BytesIO(img))
self._rects = []
self._resized_ratio_w = 1
self._resized_ratio_h = 1


def get_img(self):
"""get the image object
Expand All @@ -175,7 +154,6 @@ def get_img(self):
"""
return self._img


def get_rects(self):
"""get the rects
Expand All @@ -184,7 +162,6 @@ def get_rects(self):
"""
return self._rects


def resizing_img(self, max_height=400, max_width=400):
"""resizing the image by max_height and max_width.
Expand All @@ -210,7 +187,6 @@ def resizing_img(self, max_height=400, max_width=400):
self._resized_ratio_h = self._img.height / resized_img.height
return resized_img


def _resize_rect(self, rect):
resized_rect = {}
resized_rect["left"] = rect["left"] / self._resized_ratio_w
Expand All @@ -221,7 +197,6 @@ def _resize_rect(self, rect):
resized_rect["label"] = rect["label"]
return resized_rect


def get_resized_rects(self):
"""get resized the rects according to the resized image.
Expand All @@ -230,7 +205,6 @@ def get_resized_rects(self):
"""
return [self._resize_rect(rect) for rect in self._rects]


def _chop_box_img(self, rect):
rect["left"] = int(rect["left"] * self._resized_ratio_w)
rect["width"] = int(rect["width"] * self._resized_ratio_w)
Expand All @@ -253,25 +227,3 @@ def _chop_box_img(self, rect):
if "label" in rect:
label = rect["label"]
return (Image.fromarray(prev_img), label)


def init_annotation(self, rects):
"""init annotation for current rects.
Args:
rects(list): the bounding boxes of the image.
Returns:
prev_img(list): list of preview images with default label.
"""
self._current_rects = rects
return [self._chop_box_img(rect) for rect in self._current_rects]


def set_annotation(self, index, label):
"""set the label of the image.
Args:
index(int): the index of the list of bounding boxes of the image.
label(str): the label of the bounding box
"""
self._current_rects[index]["label"] = label
23 changes: 0 additions & 23 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@

import os

from dotenv import load_dotenv


load_dotenv()


class TestEnvVar:

def test_get_envvar(self):
api_url = os.getenv('API_URL')
dagshub_repo_owner = os.getenv('DAGSHUB_REPO_OWNER')
dagshub_repo = os.getenv('DAGSHUB_REPO')
model_uri = os.getenv('MODEL_URI')

print(f"API URL: {api_url}")
print(f"Dagshub Repo Owner: {dagshub_repo_owner}")
print(f"Dagshub Repo: {dagshub_repo}")
print(f"Model URI: {model_uri}")

assert api_url is not None
assert dagshub_repo_owner is not None
assert dagshub_repo is not None
assert model_uri is not None



Expand Down
16 changes: 15 additions & 1 deletion tests/test_required_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import os

from dotenv import load_dotenv


load_dotenv()


class TestRequiredElements:

def test_folder_exists(self):
Expand All @@ -15,7 +21,6 @@ def test_folder_exists(self):
for folder in required_folders:
assert os.path.exists(folder)


def test_file_exists(self):
required_files = ['asset/icn_save.png', 'asset/icn_shield.png',
'asset/logo_landing.png', 'asset/logo_aissyr_S.png',
Expand All @@ -32,3 +37,12 @@ def test_file_exists(self):

for file in required_files:
assert os.path.exists(file)


class TestEnvVar:

def test_get_envvar(self):
assert os.getenv('API_URL') is not None
assert os.getenv('DAGSHUB_REPO_OWNER') is not None
assert os.getenv('DAGSHUB_REPO') is not None
assert os.getenv('MODEL_URI') is not None

0 comments on commit fc3b59b

Please sign in to comment.