Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
stphivos committed Feb 24, 2021
2 parents ff5249a + ec066d6 commit 7264a32
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pyrovider/services/provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from ast import literal_eval
from typing import List, Dict, Tuple
from collections import defaultdict

Expand Down Expand Up @@ -332,5 +333,12 @@ def _get_conf(self, path: str):

def _get_env(self, var: str, default: any = None):
default = self._get_arg(default)
string = os.environ.get(var, default)

return os.environ.get(var, default)
try:
if string:
return literal_eval(string)
except SyntaxError:
pass

return string
19 changes: 19 additions & 0 deletions pyrovider/services/tests/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
import yaml

Expand Down Expand Up @@ -68,6 +69,20 @@ def test_getting_a_service_with_an_env_var_dependency_with_a_literal_default(sel
# Then...
self.assertEqual('Some default value.', service_b.some_env_var)

def test_getting_a_service_with_an_env_var_dependency_with_an_integer(self):
# When...
os.environ['INT_ENV_VAR'] = '1'
service_b = self.provider.get('service-b')
# Then...
self.assertEqual(1, service_b.some_integer)

def test_getting_a_service_with_an_env_var_dependency_with_a_boolean(self):
# When...
os.environ['BOOL_ENV_VAR'] = 'False'
service_b = self.provider.get('service-b')
# Then...
self.assertEqual(False, service_b.some_boolean)

def test_getting_a_service_with_an_env_var_dependency_with_a_config_default(self):
# When...
service_b = self.provider.get('service-b')
Expand Down Expand Up @@ -176,12 +191,16 @@ def __init__(self,
some_env_var,
other_env_var,
some_literal_value,
some_integer,
some_boolean,
password):
self.service_a = service_a
self.some_configuration = some_configuration
self.some_env_var = some_env_var
self.other_env_var = other_env_var
self.some_literal_value = some_literal_value
self.some_integer = some_integer
self.some_boolean = some_boolean
self.password = password


Expand Down
2 changes: 2 additions & 0 deletions pyrovider/services/tests/test_provider/service_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ service-b:
- [$SOME_ENV_VAR, 'Some default value.']
- [$OTHER_ENV_VAR, '%some_app.api.url%']
- 'A literal value.'
- $INT_ENV_VAR
- $BOOL_ENV_VAR
named_arguments:
password: 'default'

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.2.1', # Required
version='1.2.2', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down

0 comments on commit 7264a32

Please sign in to comment.