-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements new value_to functionality
- Loading branch information
Showing
6 changed files
with
125 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# value_to | ||
|
||
The `value_to` definition-attribute makes it possible to send the generated `value` to either STDOUT or STDERR. | ||
|
||
This can be helpful in circumstances when a quick debug reveal is required or you need to provide some kind of | ||
user response. | ||
|
||
|
||
### Example - to STDERR | ||
|
||
```yaml | ||
env-alias: | ||
|
||
EXAMPLE_STDERR: | ||
name: null | ||
value: "This is a message that will get sent to STDERR" | ||
value_to: "<STDERR>" | ||
``` | ||
### Example - to STDOUT | ||
```yaml | ||
env-alias: | ||
|
||
EXAMPLE_STDOUT_CONTENT: | ||
name: null | ||
exec: "date" | ||
|
||
EXAMPLE_STDOUT: | ||
name: null | ||
exec: 'echo "The date is ${EXAMPLE_STDOUT_CONTENT} - boom!"' | ||
value_to: "<STDOUT>" | ||
``` |
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
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
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,75 @@ | ||
import os | ||
import random | ||
import string | ||
import tempfile | ||
from pathlib import Path | ||
|
||
from env_alias.lib.generator import EnvAliasGenerator | ||
|
||
|
||
def test_value_to_stderr_01(capsys): | ||
sentinal = "XXXX_foobar01_XXXX" | ||
yaml = f""" | ||
EXAMPLE: | ||
name: null | ||
value: "{sentinal}" | ||
value_to: "<stderr>" | ||
""" | ||
|
||
config_file = __generate_config_file(yaml) | ||
EnvAliasGenerator(config_file=config_file).generate() | ||
os.unlink(config_file) | ||
|
||
captured_stderr = capsys.readouterr().err.rstrip() | ||
assert sentinal == captured_stderr | ||
|
||
captured_stdout = capsys.readouterr().out.rstrip() | ||
assert len(captured_stdout) == 0 | ||
|
||
|
||
def test_value_to_stderr_01_upper(capsys): | ||
sentinal = "XXXX_foobar01_XXXX" | ||
yaml = f""" | ||
EXAMPLE: | ||
name: null | ||
value: "{sentinal}" | ||
value_to: "<STDERR>" | ||
""" | ||
|
||
config_file = __generate_config_file(yaml) | ||
EnvAliasGenerator(config_file=config_file).generate() | ||
os.unlink(config_file) | ||
|
||
captured_stderr = capsys.readouterr().err.rstrip() | ||
assert sentinal == captured_stderr | ||
|
||
captured_stdout = capsys.readouterr().out.rstrip() | ||
assert len(captured_stdout) == 0 | ||
|
||
|
||
def test_value_to_stderr_02(capsys): | ||
sentinal = "XXXX_foobar02_XXXX" | ||
yaml = f""" | ||
EXAMPLE: | ||
name: null | ||
value: "{sentinal}" | ||
value_to: "<stdout>" | ||
""" | ||
|
||
config_file = __generate_config_file(yaml) | ||
EnvAliasGenerator(config_file=config_file).generate() | ||
os.unlink(config_file) | ||
|
||
captured_stdout = capsys.readouterr().out.rstrip() | ||
assert sentinal == captured_stdout | ||
|
||
captured_stderr = capsys.readouterr().err.rstrip() | ||
assert len(captured_stderr) == 0 | ||
|
||
|
||
def __generate_config_file(yaml_config) -> Path: | ||
config = "env-alias:" + yaml_config | ||
filename = os.path.join(tempfile.gettempdir(), "".join(random.choice(string.ascii_lowercase) for i in range(8))) | ||
with open(filename, "w") as f: | ||
f.write(config) | ||
return Path(filename) |