Skip to content
Open
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
4 changes: 3 additions & 1 deletion spectator/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class Registry:
"""Registry is the main entry point for interacting with the Spectator library."""

def __init__(self, config: Config = Config()) -> None:
def __init__(self, config: Optional[Config] = None) -> None:
if config is None:
config = Config()
self._logger = logging.getLogger(__name__)
self._config = config
if config.is_global:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import ctypes
import logging
import os
import unittest
from unittest.mock import patch

from spectator import Config, MemoryWriter, Registry


class RegistryTest(unittest.TestCase):

def test_default_config_reads_current_environment(self):
with patch.dict(os.environ, {"SPECTATOR_OUTPUT_LOCATION": "memory",
"NETFLIX_PROCESS_NAME": "worker"}):
registry = Registry()
self.addCleanup(registry.close)
self.assertIsInstance(registry.writer(), MemoryWriter)
self.assertEqual("worker", registry.new_id("requests").tags()["nf.process"])

def test_default_config_refreshes_between_registries(self):
with patch.dict(os.environ, {"SPECTATOR_OUTPUT_LOCATION": "memory",
"NETFLIX_PROCESS_NAME": "first"}):
first = Registry()
self.addCleanup(first.close)
os.environ["NETFLIX_PROCESS_NAME"] = "second"
second = Registry()
self.addCleanup(second.close)
self.assertEqual("first", first.new_id("requests").tags()["nf.process"])
self.assertEqual("second", second.new_id("requests").tags()["nf.process"])

def test_close(self):
r = Registry(Config("memory"))

Expand Down