Skip to content

Commit

Permalink
Reset temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed May 1, 2017
1 parent 2896278 commit 0b69e2d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion envdiff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(self, filename="env-diff.yml", root=None,
self.environments = environments or []

def __str__(self):
return str(self.path)
return str(self.path).replace('\\', '/')

@property
def path(self):
Expand Down
68 changes: 41 additions & 27 deletions envdiff/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned,singleton-comparison

import os
from contextlib import contextmanager

from expecter import expect

from envdiff import utils


@contextmanager
def inside(dirpath):
cwd = os.getcwd()
os.chdir(dirpath)
try:
yield
finally:
os.chdir(cwd)


def describe_init_config():

def it_sets_sample_data(tmpdir):
tmpdir.chdir()

config, created = utils.init_config()

expect(created) == True
expect(config.__mapper__.data) == dict(
sourcefiles=[
dict(path="app.json"),
dict(path=".env"),
],
environments=[
dict(name="localhost", command="env"),
dict(name="production", command="heroku run env"),
],
)
with inside(str(tmpdir)):

config, created = utils.init_config()

expect(created) == True
expect(config.__mapper__.data) == dict(
sourcefiles=[
dict(path="app.json"),
dict(path=".env"),
],
environments=[
dict(name="localhost", command="env"),
dict(name="production", command="heroku run env"),
],
)

def it_leaves_existing_files_alone(tmpdir):
tmpdir.chdir()
with open("env-diff.yml", 'w') as config_text:
config_text.write("sourcefiles: [{path: 'foo.bar'}]")

config, created = utils.init_config()

expect(created) == False
expect(config.__mapper__.data) == dict(
sourcefiles=[
dict(path="foo.bar"),
],
)
with inside(str(tmpdir)):

with open("env-diff.yml", 'w') as config_text:
config_text.write("sourcefiles: [{path: 'foo.bar'}]")

config, created = utils.init_config()

expect(created) == False
expect(config.__mapper__.data) == dict(
sourcefiles=[
dict(path="foo.bar"),
],
)
8 changes: 6 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def describe_init():
def when_config_missing(runner, tmp):
path = tmp.joinpath("env-diff.yml")
with suppress(FileNotFoundError):
print("Deleting {}".format(path))
path.unlink()

result = runner.invoke(main, ['--init'])
Expand Down Expand Up @@ -66,8 +67,9 @@ def when_config_missing(runner, tmp):

def describe_do_run():

@pytest.fixture
@pytest.yield_fixture
def config(tmpdir):
cwd = os.getcwd()
tmpdir.chdir()

with Path(".env").open('w') as f:
Expand All @@ -76,7 +78,7 @@ def config(tmpdir):
with Path("app.py").open('w') as f:
f.write("os.getenv('FOO', 2)")

return Config.new(
yield Config.new(
sourcefiles=[
SourceFile(".env"),
SourceFile("app.py"),
Expand All @@ -86,6 +88,8 @@ def config(tmpdir):
],
)

os.chdir(cwd)

def it_returns_table_data(runner, config):
print(config.sourcefiles)
data = do_run(config)
Expand Down

0 comments on commit 0b69e2d

Please sign in to comment.