Skip to content

Commit 239226a

Browse files
authored
Merge pull request #230 from AllenNeuralDynamics:fix-imports
Cleanup import logic
2 parents fb8eb5b + 4ae7589 commit 239226a

File tree

10 files changed

+46
-41
lines changed

10 files changed

+46
-41
lines changed

src/clabe/data_mapper/_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import abc
42
import logging
53
from typing import Any, Generic, Optional, TypeVar

src/clabe/data_mapper/helpers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import logging
42
import os
53
import xml.etree.ElementTree as ET
@@ -8,9 +6,7 @@
86
from typing import Dict, List, Union
97

108
import pydantic
11-
from aind_behavior_services import (
12-
AindBehaviorRigModel,
13-
)
9+
from aind_behavior_services import AindBehaviorRigModel
1410
from aind_behavior_services.rig.cameras import CameraController, CameraTypes
1511
from aind_behavior_services.utils import get_fields_of_type
1612

src/clabe/data_transfer/_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import abc
42
import logging
53
from typing import Generic, TypeVar

src/clabe/launcher/_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import asyncio
42
import hashlib
53
import logging

src/clabe/resource_monitor/_base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import logging
42
from dataclasses import dataclass, field
53
from typing import Callable, List, Optional
@@ -25,7 +23,7 @@ class ResourceMonitor(Service):
2523

2624
def __init__(
2725
self,
28-
constrains: Optional[List[Constraint]] = None,
26+
constrains: Optional[List["Constraint"]] = None,
2927
) -> None:
3028
"""
3129
Initializes the ResourceMonitor.
@@ -51,7 +49,7 @@ def run(self) -> bool:
5149
raise RuntimeError("Resource monitor constraints failed.")
5250
return result
5351

54-
def add_constraint(self, constraint: Constraint) -> None:
52+
def add_constraint(self, constraint: "Constraint") -> None:
5553
"""
5654
Adds a new constraint to the monitor.
5755
@@ -81,7 +79,7 @@ def check_memory():
8179
"""
8280
self.constraints.append(constraint)
8381

84-
def remove_constraint(self, constraint: Constraint) -> None:
82+
def remove_constraint(self, constraint: "Constraint") -> None:
8583
"""
8684
Removes a constraint from the monitor.
8785

src/clabe/resource_monitor/_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def remote_dir_exists_constraint_factory(dir_path: os.PathLike) -> Constraint:
116116
"""
117117
return Constraint(
118118
name="remote_dir_exists",
119-
constraint=lambda dir_path: os.path.exists(dir_path),
119+
constraint=os.path.exists,
120120
args=[],
121121
kwargs={"dir_path": dir_path},
122122
fail_msg_handler=lambda dir_path: f"Directory {dir_path} does not exist.",

src/clabe/utils/aind_auth.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import concurrent.futures
2-
import getpass
32
import logging
43
import platform
54
from typing import Optional
@@ -12,8 +11,6 @@
1211

1312

1413
if platform.system() == "Windows":
15-
import ldap3
16-
import ms_active_directory
1714

1815
def validate_aind_username(
1916
username: str,
@@ -46,6 +43,10 @@ def validate_aind_username(
4643
is_valid = validate_aind_username("j.doe")
4744
```
4845
"""
46+
import getpass # type: ignore[import]
47+
48+
import ldap3 # type: ignore[import]
49+
import ms_active_directory # type: ignore[import]
4950

5051
def _helper(username: str, domain: str, domain_username: Optional[str]) -> bool:
5152
"""A function submitted to a thread pool to validate the username."""

src/clabe/xml_rpc/_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
from pydantic import BaseModel, Field, HttpUrl, SecretStr
99

10-
from clabe.apps import Command
11-
from clabe.apps._base import CommandResult
12-
10+
from ..apps import Command
11+
from ..apps._base import CommandResult
1312
from ..services import ServiceSettings
1413
from ._executor import XmlRpcExecutor
1514
from .models import (

tests/test_cached_settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def test_get_latest_empty(self):
6565
class TestCacheManagerManualSync:
6666
"""Tests for CacheManager with manual sync strategy."""
6767

68+
def setup_method(self):
69+
"""Reset the cache manager before each test."""
70+
CacheManager.get_instance(reset=True, sync_strategy=SyncStrategy.MANUAL)
71+
6872
def test_register_and_add(self):
6973
"""Test registering a cache and adding values."""
7074
manager = CacheManager.get_instance(reset=True, sync_strategy=SyncStrategy.MANUAL)
@@ -147,6 +151,10 @@ def test_singleton_behavior(self):
147151
class TestCacheManagerAutoSync:
148152
"""Tests for CacheManager with auto-sync to disk."""
149153

154+
def setup_method(self):
155+
"""Reset the cache manager before each test."""
156+
CacheManager.get_instance(reset=True, sync_strategy=SyncStrategy.MANUAL)
157+
150158
def test_auto_sync_on_add(self):
151159
"""Test that AUTO sync saves after adding values."""
152160
with tempfile.TemporaryDirectory() as tmpdir:

tests/utils/test_aind_auth.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,44 @@
77

88

99
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-only test")
10-
@patch("clabe.utils.aind_auth.ms_active_directory")
11-
@patch("clabe.utils.aind_auth.ldap3")
12-
def test_validate_aind_username_windows_valid(mock_ldap3, mock_ad):
10+
def test_validate_aind_username_windows_valid():
1311
"""Test validate_aind_username on Windows with a valid user."""
14-
mock_session = MagicMock()
15-
mock_session.find_user_by_name.return_value = True
16-
mock_ad.ADDomain.return_value.create_session_as_user.return_value = mock_session
12+
with (
13+
patch("ms_active_directory.ADDomain") as mock_ad_domain,
14+
patch("ldap3.SASL", "SASL"),
15+
patch("ldap3.GSSAPI", "GSSAPI"),
16+
):
17+
mock_session = MagicMock()
18+
mock_session.find_user_by_name.return_value = True
19+
mock_ad_domain.return_value.create_session_as_user.return_value = mock_session
1720

18-
assert aind_auth.validate_aind_username("testuser")
21+
assert aind_auth.validate_aind_username("testuser")
1922

2023

2124
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-only test")
22-
@patch("clabe.utils.aind_auth.ms_active_directory")
23-
@patch("clabe.utils.aind_auth.ldap3")
24-
def test_validate_aind_username_windows_invalid(mock_ldap3, mock_ad):
25+
def test_validate_aind_username_windows_invalid():
2526
"""Test validate_aind_username on Windows with an invalid user."""
26-
mock_session = MagicMock()
27-
mock_session.find_user_by_name.return_value = None
28-
mock_ad.ADDomain.return_value.create_session_as_user.return_value = mock_session
27+
with (
28+
patch("ms_active_directory.ADDomain") as mock_ad_domain,
29+
patch("ldap3.SASL", "SASL"),
30+
patch("ldap3.GSSAPI", "GSSAPI"),
31+
):
32+
mock_session = MagicMock()
33+
mock_session.find_user_by_name.return_value = None
34+
mock_ad_domain.return_value.create_session_as_user.return_value = mock_session
2935

30-
assert not aind_auth.validate_aind_username("testuser")
36+
assert not aind_auth.validate_aind_username("testuser")
3137

3238

3339
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-only test")
34-
@patch("clabe.utils.aind_auth.ms_active_directory")
35-
@patch("clabe.utils.aind_auth.ldap3")
36-
def test_validate_aind_username_windows_timeout(mock_ldap3, mock_ad):
40+
def test_validate_aind_username_windows_timeout():
3741
"""Test validate_aind_username on Windows with a timeout."""
38-
with patch("concurrent.futures.ThreadPoolExecutor.submit") as mock_submit:
42+
with (
43+
patch("ms_active_directory.ADDomain"),
44+
patch("ldap3.SASL", "SASL"),
45+
patch("ldap3.GSSAPI", "GSSAPI"),
46+
patch("concurrent.futures.ThreadPoolExecutor.submit") as mock_submit,
47+
):
3948
mock_submit.side_effect = TimeoutError
4049
with pytest.raises(TimeoutError):
4150
aind_auth.validate_aind_username("testuser")

0 commit comments

Comments
 (0)