-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#71 Allow Environment vars to substitute/override config vars
- Loading branch information
Showing
7 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copies an input file to an output file using substitutable args. | ||
|
||
[etl] | ||
chains = input_file|output_file | ||
|
||
[input_file] | ||
class = inputs.fileinput.XmlFileInput | ||
file_path = {in_file} | ||
|
||
[output_file] | ||
class = outputs.fileoutput.FileOutput | ||
file_path = {out_file} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# testing: to be called by nosetests | ||
|
||
import os | ||
|
||
from stetl.etl import ETL | ||
from tests.stetl_test_case import StetlTestCase | ||
|
||
|
||
class ConfigTest(StetlTestCase): | ||
"""Basic configuration tests""" | ||
|
||
def setUp(self): | ||
super(ConfigTest, self).setUp() | ||
|
||
try: | ||
del os.environ['stetl_out_file'] | ||
del os.environ['stetl_in_file'] | ||
except: | ||
pass | ||
|
||
# Initialize Stetl | ||
self.curr_dir = os.path.dirname(os.path.realpath(__file__)) | ||
self.cfg_dict = {'config_file': os.path.join(self.curr_dir, 'configs/copy_in_out_file.cfg')} | ||
|
||
def test_args_dict(self): | ||
args_dict = {'in_file': 'infile.txt', 'out_file': 'outfile.txt'} | ||
etl = ETL(self.cfg_dict, args_dict) | ||
|
||
# Test args substitution from args_dict | ||
self.assertEqual(etl.configdict.get('input_file', 'file_path'), 'infile.txt') | ||
self.assertEqual(etl.configdict.get('output_file', 'file_path'), 'outfile.txt') | ||
|
||
def test_args_dict_env_override(self): | ||
args_dict = {'in_file': 'infile.txt', 'out_file': 'outfile.txt'} | ||
|
||
# Override in OS env | ||
os.environ['stetl_in_file'] = 'env_infile.txt' | ||
|
||
etl = ETL(self.cfg_dict, args_dict) | ||
|
||
# Test args substitution from args_dict | ||
self.assertEqual(etl.configdict.get('input_file', 'file_path'), os.environ['stetl_in_file']) | ||
self.assertEqual(etl.configdict.get('output_file', 'file_path'), 'outfile.txt') | ||
|
||
def test_args_dict_env_all(self): | ||
""" | ||
Substitute ALL args from OS env. | ||
:return: | ||
""" | ||
|
||
# Set all args in in OS env | ||
os.environ['stetl_in_file'] = 'env_infile.txt' | ||
os.environ['stetl_out_file'] = 'env_outfile.txt' | ||
|
||
args_dict = None | ||
etl = ETL(self.cfg_dict, args_dict) | ||
|
||
# Test args substitution from args_dict | ||
self.assertEqual(etl.configdict.get('input_file', 'file_path'), os.environ['stetl_in_file']) | ||
self.assertEqual(etl.configdict.get('output_file', 'file_path'), os.environ['stetl_out_file']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters