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
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'
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'
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)
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)
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'
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'
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"
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'
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"
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"
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
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"
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"
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
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