Skip to content

Commit

Permalink
Revise for 3.4, 2.7 compat
Browse files Browse the repository at this point in the history
Path doesn't have .write_text() in 3.4.

2.7 complains if the environment variables are typed as unicode.
  • Loading branch information
bskinn committed Mar 1, 2019
1 parent bd2c924 commit 2e584ba
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions tests/activation/test_prompts.py
Expand Up @@ -28,8 +28,11 @@
# Arbitrary prefix for the environment that's provided a 'prompt' arg
PREFIX_CUSTOM = "---ENV---"

VIRTUAL_ENV_DISABLE_PROMPT = "VIRTUAL_ENV_DISABLE_PROMPT"
VIRTUAL_ENV = "VIRTUAL_ENV"
# Py2 doesn't like unicode in the environment
def env_compat(s):
return s.encode("utf-8") if sys.version_info.major < 3 else s

VIRTUAL_ENV_DISABLE_PROMPT = env_compat("VIRTUAL_ENV_DISABLE_PROMPT")

# Filename template: {shell}.script.(normal|suppress).(default|custom)[extension]
SCRIPT_TEMPLATE = "{}.script.{}.{}{}"
Expand Down Expand Up @@ -175,31 +178,32 @@ def test_suppressed_prompt(shell, env, get_work_root, clean_env, shell_info, pla
script_name = SCRIPT_TEMPLATE.format(shell, "suppress", env, shell_info[shell].testscript_extension)
output_name = OUTPUT_TEMPLATE.format(shell, "suppress", env)

clean_env.update({VIRTUAL_ENV_DISABLE_PROMPT: "1"})
clean_env.update({VIRTUAL_ENV_DISABLE_PROMPT: env_compat("1")})

work_root = get_work_root(env)

# The extra "{prompt}" here copes with some oddity of xonsh in certain emulated terminal
# contexts: xonsh can dump stuff into the first line of the recorded script output,
# so we have to include a dummy line of output that can get munged w/o consequence.
(work_root[0] / script_name).write_text(
dedent(
"""\
with open(str(work_root[0] / script_name), "w") as f:
f.write(
dedent(
"""\
{preamble}
{prompt}
{prompt}
{act_cmd}{env}/{bindir}/{act_script}
{prompt}
""".format(
env=env,
act_cmd=shell_info[shell].activate_cmd,
preamble=shell_info[shell].preamble_cmd,
prompt=shell_info[shell].prompt_cmd,
act_script=shell_info[shell].activate_script,
bindir=work_root[1],
env=env,
act_cmd=shell_info[shell].activate_cmd,
preamble=shell_info[shell].preamble_cmd,
prompt=shell_info[shell].prompt_cmd,
act_script=shell_info[shell].activate_script,
bindir=work_root[1],
)
)
)
)

command = "{} {} > {}".format(shell_info[shell].execute_cmd, script_name, output_name)

Expand All @@ -225,9 +229,10 @@ def test_activated_prompt(shell, env, prefix, get_work_root, shell_info, platfor
# The extra "{prompt}" here copes with some oddity of xonsh in certain emulated terminal
# contexts: xonsh can dump stuff into the first line of the recorded script output,
# so we have to include a dummy line of output that can get munged w/o consequence.
(work_root[0] / script_name).write_text(
dedent(
"""\
with open(str(work_root[0] / script_name), "w") as f:
f.write(
dedent(
"""\
{preamble}
{prompt}
{prompt}
Expand All @@ -236,16 +241,16 @@ def test_activated_prompt(shell, env, prefix, get_work_root, shell_info, platfor
{deactivate}
{prompt}
""".format(
env=env,
act_cmd=shell_info[shell].activate_cmd,
deactivate=shell_info[shell].deactivate_cmd,
preamble=shell_info[shell].preamble_cmd,
prompt=shell_info[shell].prompt_cmd,
act_script=shell_info[shell].activate_script,
bindir=work_root[1],
env=env,
act_cmd=shell_info[shell].activate_cmd,
deactivate=shell_info[shell].deactivate_cmd,
preamble=shell_info[shell].preamble_cmd,
prompt=shell_info[shell].prompt_cmd,
act_script=shell_info[shell].activate_script,
bindir=work_root[1],
)
)
)
)

command = "{} {} > {}".format(shell_info[shell].execute_cmd, script_name, output_name)

Expand Down

0 comments on commit 2e584ba

Please sign in to comment.