Skip to content

Commit

Permalink
These get easier to test with Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
migurski committed Oct 27, 2016
1 parent bafffbf commit 15cd7a2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ machine:
test:
override:
- bundle exec rake
- python setup.py test
- python3 setup.py test
3 changes: 2 additions & 1 deletion metroextractor/nothingburger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import print_function
from argparse import ArgumentParser
import io

parser = ArgumentParser(description='Tell us what they told you.')

Expand All @@ -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():
Expand Down
18 changes: 7 additions & 11 deletions metroextractor/tests.py
Original file line number Diff line number Diff line change
@@ -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')
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]'))
2 changes: 1 addition & 1 deletion recipes/scripts.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15cd7a2

Please sign in to comment.