Skip to content

Commit

Permalink
update test, use generic
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Jun 2, 2020
1 parent 32e6916 commit da22b91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
from typing import Dict, Optional, Type, TypeVar, Union

ConfigValue = Union[str, bool, int, float]
_T = TypeVar("_T", ConfigValue, Optional[ConfigValue])


class Configuration:
Expand Down Expand Up @@ -148,7 +149,7 @@ def __setattr__(self, key: str, val: ConfigValue) -> None:
else:
raise AttributeError(key)

def get(self, name: str, default: ConfigValue) -> ConfigValue:
def get(self, name: str, default: _T) -> _T:
val = self._config_map.get(name, default)
return val

Expand Down
21 changes: 13 additions & 8 deletions opentelemetry-api/tests/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_singleton(self) -> None:
"OPENTELEMETRY_PTHON_TRACEX_PROVIDER": "tracex_provider",
},
)
def test_environment_variables(self): # type: ignore
def test_environment_variables(self):
self.assertEqual(
Configuration().METER_PROVIDER, "meter_provider"
) # pylint: disable=no-member
Expand All @@ -62,16 +62,21 @@ def test_property(self):
with self.assertRaises(AttributeError):
Configuration().TRACER_PROVIDER = "new_tracer_provider"

def test_slots(self):
def test_slots(self) -> None:
with self.assertRaises(AttributeError):
Configuration().XYZ = "xyz" # pylint: disable=assigning-non-slot

def test_getattr(self):
def test_getattr(self) -> None:
# literal access
self.assertIsNone(Configuration().XYZ)

def test_reset(self):
# dynamic access
self.assertIsNone(getattr(Configuration(), "XYZ"))
self.assertIsNone(Configuration().get("XYZ", None))

def test_reset(self) -> None:
environ_patcher = patch.dict(
"os.environ", # type: ignore
"os.environ",
{"OPENTELEMETRY_PYTHON_TRACER_PROVIDER": "tracer_provider"},
)

Expand All @@ -96,7 +101,7 @@ def test_reset(self):
"OPENTELEMETRY_PYTHON_FALSE": "False",
},
)
def test_boolean(self):
def test_boolean(self) -> None:
self.assertIsInstance(
Configuration().TRUE, bool
) # pylint: disable=no-member
Expand All @@ -114,7 +119,7 @@ def test_boolean(self):
"OPENTELEMETRY_PYTHON_NON_INTEGER": "-12z3",
},
)
def test_integer(self):
def test_integer(self) -> None:
self.assertEqual(
Configuration().POSITIVE_INTEGER, 123
) # pylint: disable=no-member
Expand All @@ -133,7 +138,7 @@ def test_integer(self):
"OPENTELEMETRY_PYTHON_NON_FLOAT": "-12z3.123",
},
)
def test_float(self):
def test_float(self) -> None:
self.assertEqual(
Configuration().POSITIVE_FLOAT, 123.123
) # pylint: disable=no-member
Expand Down

0 comments on commit da22b91

Please sign in to comment.