Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/superannotate/lib/app/interface/base_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, token: TokenStr = None, config_path: str = None):
if token:
config = ConfigEntity(SA_TOKEN=token)
elif config_path:
config_path = Path(config_path)
config_path = Path(config_path).expanduser()
if not Path(config_path).is_file() or not os.access(
config_path, os.R_OK
):
Expand Down
3 changes: 2 additions & 1 deletion src/superannotate/lib/core/__init__.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change to logger.debug(e) on line 63

Copy link
Contributor Author

@nareksa nareksa Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def setup_logging(level=DEFAULT_LOGGING_LEVEL, file_path=LOG_FILE_LOCATION):
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
try:
os.makedirs(file_path, exist_ok=True)
log_file_path = os.path.join(file_path, "sa.log")
open(log_file_path, "w").close()
if os.access(log_file_path, os.W_OK):
Expand All @@ -59,7 +60,7 @@ def setup_logging(level=DEFAULT_LOGGING_LEVEL, file_path=LOG_FILE_LOCATION):
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
except OSError as e:
logging.error(e)
logger.debug(e)


DEFAULT_IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "tif", "tiff", "webp", "bmp"]
Expand Down
33 changes: 29 additions & 4 deletions tests/unit/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import tempfile
from configparser import ConfigParser
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch

Expand Down Expand Up @@ -30,7 +31,6 @@ def test_init_via_token(self, get_team_use_case):
@patch("lib.core.usecases.GetTeamUseCase")
def test_init_via_config_json(self, get_team_use_case):
with tempfile.TemporaryDirectory() as config_dir:
constants.HOME_PATH = config_dir
config_ini_path = f"{config_dir}/config.ini"
config_json_path = f"{config_dir}/config.json"
with patch("lib.core.CONFIG_INI_FILE_LOCATION", config_ini_path), patch(
Expand All @@ -48,7 +48,6 @@ def test_init_via_config_json(self, get_team_use_case):

def test_init_via_config_json_invalid_json(self):
with tempfile.TemporaryDirectory() as config_dir:
constants.HOME_PATH = config_dir
config_ini_path = f"{config_dir}/config.ini"
config_json_path = f"{config_dir}/config.json"
with patch("lib.core.CONFIG_INI_FILE_LOCATION", config_ini_path), patch(
Expand All @@ -65,7 +64,6 @@ def test_init_via_config_json_invalid_json(self):
@patch("lib.core.usecases.GetTeamUseCase")
def test_init_via_config_ini(self, get_team_use_case):
with tempfile.TemporaryDirectory() as config_dir:
constants.HOME_PATH = config_dir
config_ini_path = f"{config_dir}/config.ini"
config_json_path = f"{config_dir}/config.json"
with patch("lib.core.CONFIG_INI_FILE_LOCATION", config_ini_path), patch(
Expand All @@ -88,6 +86,34 @@ def test_init_via_config_ini(self, get_team_use_case):
self._token.split("=")[-1]
)

@patch("lib.core.usecases.GetTeamUseCase")
def test_init_via_config_relative_filepath(self, get_team_use_case):
with tempfile.TemporaryDirectory(dir=Path("~").expanduser()) as config_dir:
config_ini_path = f"{config_dir}/config.ini"
config_json_path = f"{config_dir}/config.json"
with patch("lib.core.CONFIG_INI_FILE_LOCATION", config_ini_path), patch(
"lib.core.CONFIG_JSON_FILE_LOCATION", config_json_path
):
with open(f"{config_dir}/config.ini", "w") as config_ini:
config_parser = ConfigParser()
config_parser.optionxform = str
config_parser["DEFAULT"] = {
"SA_TOKEN": self._token,
"LOGGING_LEVEL": "DEBUG",
}
config_parser.write(config_ini)
for kwargs in (
{},
{"config_path": f"~/{Path(config_dir).name}/config.ini"},
):
sa = SAClient(**kwargs)
assert sa.controller._config.API_TOKEN == self._token
assert sa.controller._config.LOGGING_LEVEL == "DEBUG"
assert sa.controller._config.API_URL == constants.BACKEND_URL
assert get_team_use_case.call_args_list[0].kwargs["team_id"] == int(
self._token.split("=")[-1]
)

@patch("lib.core.usecases.GetTeamUseCase")
@patch.dict(os.environ, {"SA_URL": "SOME_URL", "SA_TOKEN": "SOME_TOKEN=123"})
def test_init_env(self, get_team_use_case):
Expand All @@ -103,7 +129,6 @@ def test_init_env_invalid_token(self):

def test_init_via_config_ini_invalid_token(self):
with tempfile.TemporaryDirectory() as config_dir:
constants.HOME_PATH = config_dir
config_ini_path = f"{config_dir}/config.ini"
config_json_path = f"{config_dir}/config.json"
with patch("lib.core.CONFIG_INI_FILE_LOCATION", config_ini_path), patch(
Expand Down