예제 #1
0
def test_console_script(cli):
    TEST_COMBINATIONS = (
        # quote_mode, var_name, var_value, expected_result
        ("always", "HELLO", "WORLD", 'HELLO="WORLD"\n'),
        ("never", "HELLO", "WORLD", 'HELLO=WORLD\n'),
        ("auto", "HELLO", "WORLD", 'HELLO=WORLD\n'),
        ("auto", "HELLO", "HELLO WORLD", 'HELLO="HELLO WORLD"\n'),
    )
    with cli.isolated_filesystem():
        for quote_mode, variable, value, expected_result in TEST_COMBINATIONS:
            sh.touch(dotenv_path)
            sh.dotenv('-f', dotenv_path, '-q', quote_mode, 'set', variable, value)
            output = sh.cat(dotenv_path)
            assert output == expected_result
            sh.rm(dotenv_path)

    # should fail for not existing file
    result = cli.invoke(dotenv.cli.set, ['my_key', 'my_value'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.cli.get, ['my_key'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.cli.list, [])
    assert result.exit_code != 0
예제 #2
0
def test_run_with_other_env(tmp_path):
    dotenv_name = 'dotenv'
    dotenv_file = tmp_path / dotenv_name
    dotenv_file.touch()
    sh.cd(str(tmp_path))
    sh.dotenv('--file', dotenv_name, 'set', 'FOO', 'BAR')
    result = sh.dotenv('--file', dotenv_name, 'run', 'printenv', 'FOO').strip()
    assert result == 'BAR'
예제 #3
0
def test_default_path(tmp_path):
    sh.cd(str(tmp_path))
    sh.touch(tmp_path / '.env')
    sh.dotenv('set', 'HELLO', 'WORLD')

    result = sh.dotenv('get', 'HELLO')

    assert result == 'HELLO=WORLD\n'
예제 #4
0
def test_default_path(cli):
    with cli.isolated_filesystem():
        sh.touch(dotenv_path)
        sh.cd(here)
        sh.dotenv('set', 'HELLO', 'WORLD')
        output = sh.dotenv('get', 'HELLO')
        assert output == 'HELLO="WORLD"\n'
        sh.rm(dotenv_path)
예제 #5
0
def test_default_path(cli):
    with cli.isolated_filesystem():
        sh.touch(dotenv_path)
        sh.cd(here)
        sh.dotenv('set', 'HELLO', 'WORLD')
        output = sh.dotenv('get', 'HELLO')
        assert output == 'HELLO=WORLD\n'
        sh.rm(dotenv_path)
예제 #6
0
def test_run_with_other_env(cli):
    DOTENV_FILE = 'dotenv'
    with cli.isolated_filesystem():
        sh.cd(here)
        sh.touch(DOTENV_FILE)
        sh.dotenv('--file', DOTENV_FILE, 'set', 'FOO', 'BAR')
        result = sh.dotenv('--file', DOTENV_FILE, 'run', 'printenv',
                           'FOO').strip()
        assert result == 'BAR'
예제 #7
0
def test_run(tmp_path):
    dotenv_file = tmp_path / '.env'
    dotenv_file.touch()
    sh.cd(str(tmp_path))
    dotenv.set_key(str(dotenv_file), 'FOO', 'BAR')
    result = sh.dotenv('run', 'printenv', 'FOO').strip()
    assert result == 'BAR'
예제 #8
0
def test_run(tmp_path):
    dotenv_file = tmp_path / '.env'
    dotenv_file.touch()
    sh.cd(str(tmp_path))
    dotenv.set_key(str(dotenv_file), 'FOO', 'BAR')
    result = sh.dotenv('run', 'printenv', 'FOO').strip()
    assert result == 'BAR'
예제 #9
0
def test_run_with_other_env(dotenv_file):
    with open(dotenv_file, "w") as f:
        f.write("a=b")

    result = sh.dotenv("--file", dotenv_file, "run", "printenv", "a")

    assert result == "b\n"
예제 #10
0
def test_run(cli):
    with cli.isolated_filesystem():
        sh.touch(dotenv_path)
        sh.cd(here)
        dotenv.set_key(dotenv_path, 'FOO', 'BAR')
        result = sh.dotenv('run', 'printenv', 'FOO').strip()
        assert result == 'BAR'
예제 #11
0
def test_get_default_path(tmp_path):
    sh.cd(str(tmp_path))
    with open(str(tmp_path / ".env"), "w") as f:
        f.write("a=b")

    result = sh.dotenv("get", "a")

    assert result == "b\n"
예제 #12
0
def test_run_with_none_value(tmp_path):
    sh.cd(str(tmp_path))
    dotenv_file = str(tmp_path / ".env")
    with open(dotenv_file, "w") as f:
        f.write("a=b\nc")

    result = sh.dotenv("run", "printenv", "a")

    assert result == "b\n"
예제 #13
0
def test_console_script(cli):
    with cli.isolated_filesystem():
        sh.touch(dotenv_path)
        sh.dotenv('-f', dotenv_path, 'set', 'HELLO', 'WORLD')
        output = sh.dotenv('-f', dotenv_path, 'get', 'HELLO', )
        assert output == 'HELLO="WORLD"\n'
        sh.rm(dotenv_path)

    # should fail for not existing file
    result = cli.invoke(dotenv.set, ['my_key', 'my_value'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.get, ['my_key'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.list, [])
    assert result.exit_code != 0
예제 #14
0
def test_run_with_existing_variable_not_overridden(tmp_path):
    sh.cd(str(tmp_path))
    dotenv_file = str(tmp_path / ".env")
    with open(dotenv_file, "w") as f:
        f.write("a=b")
    env = dict(os.environ)
    env.update({"LANG": "en_US.UTF-8", "a": "c"})

    result = sh.dotenv("run", "--no-override", "printenv", "a", _env=env)

    assert result == "c\n"
예제 #15
0
def test_run_with_existing_variable(tmp_path):
    sh.cd(str(tmp_path))
    dotenv_file = str(tmp_path / ".env")
    with open(dotenv_file, "w") as f:
        f.write("a=b")

    result = sh.dotenv("run",
                       "printenv",
                       "a",
                       _env={
                           "LANG": "en_US.UTF-8",
                           "a": "c"
                       })

    assert result == "b\n"
예제 #16
0
def test_console_script(cli):
    with cli.isolated_filesystem():
        sh.touch(dotenv_path)
        sh.dotenv('-f', dotenv_path, 'set', 'HELLO', 'WORLD')
        output = sh.dotenv(
            '-f',
            dotenv_path,
            'get',
            'HELLO',
        )
        assert output == 'HELLO="WORLD"\n'
        sh.rm(dotenv_path)

    # should fail for not existing file
    result = cli.invoke(dotenv.set, ['my_key', 'my_value'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.get, ['my_key'])
    assert result.exit_code != 0

    # should fail for not existing file
    result = cli.invoke(dotenv.list, [])
    assert result.exit_code != 0
예제 #17
0
def test_console_script(quote_mode, variable, value, expected, dotenv_file):
    sh.dotenv('-f', dotenv_file, '-q', quote_mode, 'set', variable, value)

    result = sh.cat(dotenv_file)

    assert result == expected
예제 #18
0
def test_console_script(quote_mode, variable, value, expected, dotenv_file):
    sh.dotenv('-f', dotenv_file, '-q', quote_mode, 'set', variable, value)

    result = sh.cat(dotenv_file)

    assert result == expected