From ff701183170c29b86350ce6c9e8614b141308098 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 10 Sep 2019 16:46:09 +0300 Subject: [PATCH] Version 1.1.1 release --- CHANGELOG.md | 7 +++ dump_env/cli.py | 2 +- pyproject.toml | 2 +- tests/test_cli.py | 87 ---------------------------------- tests/test_cli/test_general.py | 48 +++++++++++++++++++ tests/test_cli/test_help.py | 13 +++++ tests/test_cli/test_strict.py | 44 +++++++++++++++++ 7 files changed, 114 insertions(+), 89 deletions(-) delete mode 100644 tests/test_cli.py create mode 100644 tests/test_cli/test_general.py create mode 100644 tests/test_cli/test_help.py create mode 100644 tests/test_cli/test_strict.py diff --git a/CHANGELOG.md b/CHANGELOG.md index bb97c1c..154c9b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ We follow semantic versioning. +## Version 1.1.1 + +### Bugfixes + +- Outputs errors to `stderr` instead of `stdout` + + ## Version 1.1.0 ### Features diff --git a/dump_env/cli.py b/dump_env/cli.py index e35e329..0ba4a3b 100644 --- a/dump_env/cli.py +++ b/dump_env/cli.py @@ -77,7 +77,7 @@ def main() -> NoReturn: try: variables = dump(args.template, args.prefix, strict_vars) except StrictEnvException as exc: - sys.stdout.write('{0}\n'.format(str(exc))) + sys.stderr.write('{0}\n'.format(str(exc))) sys.exit(1) else: for env_name, env_value in variables.items(): diff --git a/pyproject.toml b/pyproject.toml index 3b7ac37..ba201d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ style = "https://raw.githubusercontent.com/wemake-services/wemake-python-stylegu [tool.poetry] name = "dump-env" -version = "1.1.0" +version = "1.1.1" description = "A utility tool to create .env files" license = "MIT" diff --git a/tests/test_cli.py b/tests/test_cli.py deleted file mode 100644 index 2723bd5..0000000 --- a/tests/test_cli.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- coding: utf-8 -*- - -import delegator - - -def test_help_option(): - """Check that cli shows help.""" - variables = delegator.run('dump-env --help') - assert 'show this help message and exit' in variables.out - assert '--template TEMPLATE' in variables.out - assert '--prefix PREFIX' in variables.out - assert variables.subprocess.returncode == 0 - - -def test_simple_usage(monkeypatch): - """Check that cli shows prefixed variables.""" - monkeypatch.setenv('SOM_TT_VALUE', '1') - - variables = delegator.run('dump-env -p SOM_TT_') - assert variables.out == 'VALUE=1\n' - - -def test_both_options(monkeypatch, env_file): - """ - Check with template and prefix. - - CLI must show all prefixed variables by template. - """ - monkeypatch.setenv('SOM_TT_VALUE', '1') - - variables = delegator.run('dump-env -p SOM_TT_ -t {0}'.format(env_file)) - assert variables.out == 'NORMAL_KEY=SOMEVALUE\nVALUE=1\n' - - -def test_multiple_prefixes(monkeypatch): - """ - Check that CLI with multiple prefixes. - - CLI must show all prefixed variables correctly. - """ - monkeypatch.setenv('SOM_TT_VALUE', '1') - monkeypatch.setenv('ANOTHER_TT_VALUE', '2') - - variables = delegator.run('dump-env -p SOM_TT_ -p ANOTHER_TT_') - assert variables.out == 'VALUE=2\n' - - -def test_simple_usage_file_output(monkeypatch, tmpdir): - """Check that CLI puts prefixed variables into file correctly.""" - monkeypatch.setenv('SOM_TT_VALUE', '1') - - filename = tmpdir.mkdir('tests').join('.env').strpath - - delegator.run('dump-env -p SOM_TT_ > {0}'.format(filename)) - - with open(filename) as env_file: - assert env_file.read() == 'VALUE=1\n' - - -def test_strict_vars(monkeypatch): - """Check that cli works correctly with strict vars.""" - monkeypatch.setenv('SOM_TT_VALUE', '1') - monkeypatch.setenv('SOM_TT_KEY', '2') - - variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') - assert variables.out == 'KEY=2\nVALUE=1\n' - assert variables.subprocess.returncode == 0 - - variables = delegator.run( - 'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', - ) - assert variables.out == 'KEY=2\nVALUE=1\n' - assert variables.subprocess.returncode == 0 - - -def test_strict_missing_vars(monkeypatch): - """Check that cli raises errors for missing strict keys.""" - variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') - assert variables.out == 'Missing env vars: SOM_TT_KEY\n' - assert variables.subprocess.returncode == 1 - - variables = delegator.run( - 'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', - ) - assert 'SOM_TT_VALUE' in variables.out - assert 'SOM_TT_KEY' in variables.out - assert variables.subprocess.returncode == 1 diff --git a/tests/test_cli/test_general.py b/tests/test_cli/test_general.py new file mode 100644 index 0000000..f8f2518 --- /dev/null +++ b/tests/test_cli/test_general.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import delegator + + +def test_simple_usage(monkeypatch): + """Check that cli shows prefixed variables.""" + monkeypatch.setenv('SOM_TT_VALUE', '1') + + variables = delegator.run('dump-env -p SOM_TT_') + assert variables.out == 'VALUE=1\n' + + +def test_both_options(monkeypatch, env_file): + """ + Check with template and prefix. + + CLI must show all prefixed variables by template. + """ + monkeypatch.setenv('SOM_TT_VALUE', '1') + + variables = delegator.run('dump-env -p SOM_TT_ -t {0}'.format(env_file)) + assert variables.out == 'NORMAL_KEY=SOMEVALUE\nVALUE=1\n' + + +def test_multiple_prefixes(monkeypatch): + """ + Check that CLI with multiple prefixes. + + CLI must show all prefixed variables correctly. + """ + monkeypatch.setenv('SOM_TT_VALUE', '1') + monkeypatch.setenv('ANOTHER_TT_VALUE', '2') + + variables = delegator.run('dump-env -p SOM_TT_ -p ANOTHER_TT_') + assert variables.out == 'VALUE=2\n' + + +def test_simple_usage_file_output(monkeypatch, tmpdir): + """Check that CLI puts prefixed variables into file correctly.""" + monkeypatch.setenv('SOM_TT_VALUE', '1') + + filename = tmpdir.mkdir('tests').join('.env').strpath + + delegator.run('dump-env -p SOM_TT_ > {0}'.format(filename)) + + with open(filename) as env_file: + assert env_file.read() == 'VALUE=1\n' diff --git a/tests/test_cli/test_help.py b/tests/test_cli/test_help.py new file mode 100644 index 0000000..61f9a02 --- /dev/null +++ b/tests/test_cli/test_help.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +import delegator + + +def test_help_option(): + """Check that cli shows help.""" + variables = delegator.run('dump-env --help') + assert 'show this help message and exit' in variables.out + assert '--template TEMPLATE' in variables.out + assert '--prefix PREFIX' in variables.out + assert '--strict' in variables.out + assert variables.subprocess.returncode == 0 diff --git a/tests/test_cli/test_strict.py b/tests/test_cli/test_strict.py new file mode 100644 index 0000000..49fe268 --- /dev/null +++ b/tests/test_cli/test_strict.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +import delegator + + +def test_strict_vars1(monkeypatch): + """Check that cli works correctly with strict vars.""" + monkeypatch.setenv('SOM_TT_VALUE', '1') + monkeypatch.setenv('SOM_TT_KEY', '2') + + variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') + assert variables.out == 'KEY=2\nVALUE=1\n' + assert variables.subprocess.returncode == 0 + + +def test_strict_vars2(monkeypatch): + """Check that cli works correctly with strict vars.""" + monkeypatch.setenv('SOM_TT_VALUE', '1') + monkeypatch.setenv('SOM_TT_KEY', '2') + + variables = delegator.run( + 'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', + ) + assert variables.out == 'KEY=2\nVALUE=1\n' + assert variables.subprocess.returncode == 0 + + +def test_strict_missing_vars1(monkeypatch): + """Check that cli raises errors for missing strict keys.""" + variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') + assert variables.out == '' + assert variables.err == 'Missing env vars: SOM_TT_KEY\n' + assert variables.subprocess.returncode == 1 + + +def test_strict_missing_vars2(monkeypatch): + """Check that cli raises errors for missing strict keys.""" + variables = delegator.run( + 'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', + ) + assert variables.out == '' + assert 'SOM_TT_VALUE' in variables.err + assert 'SOM_TT_KEY' in variables.err + assert variables.subprocess.returncode == 1