Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use built-in
open
whenever possible (#208)
* added integration test * Resolving issue #207: use built-in open whenever possible * rename integration test using correct issue number * update unit tests * isolate failing test case * Updated unit tests Changed the mock target to keep in step with the shortcut_open function. Split tests into separate test cases. * respond to review comments - use tempfile instead of hard-coded file - integrate new test into travis.yml so that Travis runs it * added support for buffering parameter
- Loading branch information
1 parent
20c6c93
commit 1c43f19
Showing
4 changed files
with
137 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
try: | ||
import numpy as np | ||
except ImportError: | ||
print("You really need numpy to proceed with this test") | ||
sys.exit(1) | ||
|
||
import smart_open | ||
|
||
|
||
def tofile(): | ||
dt = np.dtype([('time', [('min', int), ('sec', int)]), ('temp', float)]) | ||
x = np.zeros((1,), dtype=dt) | ||
|
||
with tempfile.NamedTemporaryFile(prefix='test_207', suffix='.dat', delete=False) as fout: | ||
x.tofile(fout.name) | ||
return fout.name | ||
|
||
|
||
def test(): | ||
try: | ||
path = tofile() | ||
with smart_open.smart_open(path, 'rb') as fin: | ||
loaded = np.fromfile(fin) | ||
return 0 | ||
finally: | ||
os.unlink(path) | ||
return 1 | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(test()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters