Skip to content

Commit

Permalink
Fixed broken smart_open
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucretiel committed Aug 15, 2017
1 parent 88064c2 commit 34aafaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/autocommand/autoparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def work_with_file(name=sys.stdout):
# If it was a filename, f is closed at the end here.
'''
if isinstance(filename_or_file, (str, bytes, int)):
with open(filename_or_file) as file:
with open(filename_or_file, *args, **kwargs) as file:
yield file
else:
yield filename_or_file
29 changes: 26 additions & 3 deletions test/test_autoparse/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@ def test_smart_open_is_exported():
assert autocommand.smart_open is smart_open


def test_smart_open_path(tmpdir):
path = str(tmpdir.join('file.txt').ensure(file=True))
def test_smart_open_path_read(tmpdir):
target = tmpdir.join('file.txt')
target.write("Hello")

with smart_open(str(target)) as file:
assert not file.closed
assert file.read() == "Hello"

assert file.closed


with smart_open(path, 'w') as file:
def test_smart_open_path_write(tmpdir):
target = tmpdir.join('file.txt').ensure(file=True)

with smart_open(str(target), 'w') as file:
assert not file.closed
file.write("Test Content") # Tests that the file is writable

assert file.closed
assert target.read() == "Test Content"


def test_smart_open_path_create(tmpdir):
target = tmpdir.join("file.txt")

with smart_open(str(target), 'w') as file:
file.write("Test Content")

assert target.read() == "Test Content"


def test_smart_open_file(tmpdir):
Expand Down

0 comments on commit 34aafaf

Please sign in to comment.