diff --git a/circle.yml b/circle.yml index 41ae5ba..a477d80 100644 --- a/circle.yml +++ b/circle.yml @@ -4,4 +4,4 @@ machine: test: override: - bundle exec rake - - python setup.py test + - python3 setup.py test diff --git a/metroextractor/nothingburger.py b/metroextractor/nothingburger.py index 27a8dc0..b356bc5 100644 --- a/metroextractor/nothingburger.py +++ b/metroextractor/nothingburger.py @@ -1,5 +1,6 @@ from __future__ import print_function from argparse import ArgumentParser +import io parser = ArgumentParser(description='Tell us what they told you.') @@ -12,7 +13,7 @@ def tell_us(bbox, filename): ''' ''' - with open(filename, 'w') as file: + with io.open(filename, 'w') as file: print(bbox, file=file) def main(): diff --git a/metroextractor/tests.py b/metroextractor/tests.py index 846e6dd..5686861 100644 --- a/metroextractor/tests.py +++ b/metroextractor/tests.py @@ -1,17 +1,13 @@ -import unittest, tempfile, os +import unittest, unittest.mock from . import nothingburger class Nothingburger (unittest.TestCase): - def setUp(self): - handle, self.filename = tempfile.mkstemp() - os.close(handle) - - def tearDown(self): - os.remove(self.filename) - def test_tell_us(self): - nothingburger.tell_us([0, 1, 2, 3], self.filename) - with open(self.filename) as file: - self.assertEqual(next(file), '[0, 1, 2, 3]\n') \ No newline at end of file + with unittest.mock.patch('io.open') as io_open: + nothingburger.tell_us([0, 1, 2, 3], 'filename.txt') + + io_open.assert_called_once_with('filename.txt', 'w') + write_call = io_open.return_value.__enter__.return_value.mock_calls[0] + self.assertTrue(write_call[1][0].startswith('[0, 1, 2, 3]')) diff --git a/recipes/scripts.rb b/recipes/scripts.rb index f821633..e54d7fe 100644 --- a/recipes/scripts.rb +++ b/recipes/scripts.rb @@ -1,4 +1,4 @@ -execute 'pip install -U .' do +execute 'pip3 install -U .' do cwd File.join(File.dirname(__FILE__), '..') environment('LC_ALL' => 'C.UTF-8') # ...for correct encoding in python open() end