Skip to content

Commit

Permalink
change db file variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertdeng123 committed Nov 1, 2024
1 parent c9bd5cc commit a776e9d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion devservices/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DEVSERVICES_LOCAL_DIR = os.path.expanduser("~/.local/share/sentry-devservices")
DEVSERVICES_DEPENDENCIES_CACHE_DIR = os.path.join(DEVSERVICES_CACHE_DIR, "dependencies")
DEVSERVICES_DEPENDENCIES_CACHE_DIR_KEY = "DEVSERVICES_DEPENDENCIES_CACHE_DIR"
DB_FILE = os.path.join(DEVSERVICES_LOCAL_DIR, "state")
STATE_DB_FILE = os.path.join(DEVSERVICES_LOCAL_DIR, "state")

DEPENDENCY_CONFIG_VERSION = "v1"
DEPENDENCY_GIT_PARTIAL_CLONE_CONFIG_OPTIONS = {
Expand Down
8 changes: 4 additions & 4 deletions devservices/utils/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import os
import sqlite3

from devservices.constants import DB_FILE
from devservices.constants import DEVSERVICES_LOCAL_DIR
from devservices.constants import STATE_DB_FILE


class State:
_instance: State | None = None
db_file: str
state_db_file: str
conn: sqlite3.Connection

def __new__(cls) -> State:
if cls._instance is None:
cls._instance = super(State, cls).__new__(cls)
if not os.path.exists(DEVSERVICES_LOCAL_DIR):
os.makedirs(DEVSERVICES_LOCAL_DIR)
cls._instance.db_file = DB_FILE
cls._instance.conn = sqlite3.connect(cls._instance.db_file)
cls._instance.state_db_file = STATE_DB_FILE
cls._instance.conn = sqlite3.connect(cls._instance.state_db_file)
cls._instance.initialize_database()
return cls._instance

Expand Down
12 changes: 6 additions & 6 deletions tests/utils/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@


def test_state_simple(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
assert state.get_started_services() == []


def test_state_add_started_service(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
state.add_started_service("example-service", "default")
assert state.get_started_services() == ["example-service"]
assert state.get_mode_for_service("example-service") == "default"


def test_state_remove_started_service(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
state.add_started_service("example-service", "default")
assert state.get_started_services() == ["example-service"]
Expand All @@ -31,14 +31,14 @@ def test_state_remove_started_service(tmp_path: Path) -> None:


def test_state_remove_unknown_service(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
state.remove_started_service("unknown-service")
assert state.get_started_services() == []


def test_start_service_twice(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
state.add_started_service("example-service", "default")
assert state.get_started_services() == ["example-service"]
Expand All @@ -49,6 +49,6 @@ def test_start_service_twice(tmp_path: Path) -> None:


def test_get_mode_for_nonexistent_service(tmp_path: Path) -> None:
with mock.patch("devservices.utils.state.DB_FILE", str(tmp_path / "state")):
with mock.patch("devservices.utils.state.STATE_DB_FILE", str(tmp_path / "state")):
state = State()
assert state.get_mode_for_service("unknown-service") is None

0 comments on commit a776e9d

Please sign in to comment.