Skip to content

Commit

Permalink
Merge pull request #11 from jacebrowning/fix-windows-ci
Browse files Browse the repository at this point in the history
Update tests to run on Windows
  • Loading branch information
jacebrowning committed May 1, 2017
2 parents 2896278 + 64d8a5e commit faba192
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 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"),
],
)
2 changes: 1 addition & 1 deletion envdiff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ def write_markdown(rows, path):
def write_csv(rows, path):
log.info("Writing to %s", path)
with path.open('w') as file:
csvfile = csv.writer(file)
csvfile = csv.writer(file, lineterminator='\n')
for row in rows:
csvfile.writerow(row)
19 changes: 12 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def runner():


@pytest.yield_fixture
def tmp(path=Path("tmp", "int", "cli").resolve()):
def tmp():
cwd = Path.cwd()
path.mkdir(parents=True, exist_ok=True)
os.chdir(path)
yield path
dirpath = Path("tmp", "int", "cli").resolve()
dirpath.mkdir(parents=True, exist_ok=True)
os.chdir(dirpath)
yield dirpath
os.chdir(cwd)


Expand All @@ -36,8 +37,9 @@ def describe_cli():
def describe_init():

def when_config_missing(runner, tmp):
path = tmp.joinpath("env-diff.yml")
path = tmp.joinpath("env-diff.yml").resolve()
with suppress(FileNotFoundError):
print("Deleting {}".format(path))
path.unlink()

result = runner.invoke(main, ['--init'])
Expand Down Expand Up @@ -66,8 +68,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 +79,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 +89,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 faba192

Please sign in to comment.