Skip to content
Browse files

Clean up filehandle pattern

  • Loading branch information...
1 parent e9a7149 commit 499cae56add397581bf1ed88e926c0b54cd42ef7 @djs committed May 25, 2015
Showing with 4 additions and 7 deletions.
  1. +4 −7 test_elm.py
View
11 test_elm.py
@@ -21,13 +21,11 @@ def __init__(self):
self.spaces = True
self.state = self.State.RESET
- fh = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm.json'), 'r')
- self.command_table_h0 = json.load(fh)
- fh.close()
+ with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm.json'), 'r') as fh:
+ self.command_table_h0 = json.load(fh)
- fh = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm_h1.json'), 'r')
- self.command_table_h1 = json.load(fh)
- fh.close()
+ with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm_h1.json'), 'r') as fh:
+ self.command_table_h1 = json.load(fh)
self._set_h0()
@@ -156,4 +154,3 @@ def test_send_obdii_command_with_ml_resp(self):
data = self.elm.send_obdii_command([0x09, 0x02])
assert data == expected_response
print ''.join(chr(i) for i in data[0x7e8][3:])
-

0 comments on commit 499cae5

Please sign in to comment.
Something went wrong with that request. Please try again.