Skip to content

Commit 0ecc72b

Browse files
committed
python 3 compatibility
1 parent 0a17948 commit 0ecc72b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

pluginloader/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def load_file(self, filename, onlyif=None):
2424
with open(filename) as fd:
2525
exec(fd.read(), context)
2626

27-
for name, clazz in context.iteritems():
27+
for name, clazz in context.items():
2828
if (self._apply_condition(onlyif, name, clazz)):
2929
self.plugins[name] = PluginFactory(clazz)
3030

tests/integration/test_file_loader.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def setUp(self):
1313
def tearDown(self):
1414
self.plugin_file.close()
1515

16+
def _write_file(self, content):
17+
self.plugin_file.write(content.encode('utf-8'))
18+
1619
def test_load_empty_file(self):
1720
sut = PluginLoader()
1821

@@ -21,7 +24,7 @@ def test_load_empty_file(self):
2124
self.assertEquals({}, sut.plugins)
2225

2326
def test_base_case(self):
24-
self.plugin_file.write('class Foo(object): pass')
27+
self._write_file('class Foo(object): pass')
2528
self.plugin_file.flush()
2629
sut = PluginLoader()
2730

@@ -32,7 +35,7 @@ def test_base_case(self):
3235
self.assertEquals('Foo', sut.plugins['Foo']().__class__.__name__)
3336

3437
def test_ignorable_classes(self):
35-
self.plugin_file.write('class Foo(object): pass')
38+
self._write_file('class Foo(object): pass')
3639
self.plugin_file.flush()
3740
sut = PluginLoader()
3841

@@ -41,7 +44,7 @@ def test_ignorable_classes(self):
4144
self.assertEquals({}, sut.plugins)
4245

4346
def test_ignorable_classes_with_variable_false(self):
44-
self.plugin_file.write('class Foo(object): pass')
47+
self._write_file('class Foo(object): pass')
4548
self.plugin_file.flush()
4649
sut = PluginLoader()
4750

@@ -50,7 +53,7 @@ def test_ignorable_classes_with_variable_false(self):
5053
self.assertEquals([], sut.plugins.keys())
5154

5255
def test_ignorable_classes_with_variable_true(self):
53-
self.plugin_file.write('class Foo(object): pass')
56+
self._write_file('class Foo(object): pass')
5457
self.plugin_file.flush()
5558
sut = PluginLoader()
5659

@@ -59,7 +62,7 @@ def test_ignorable_classes_with_variable_true(self):
5962
self.assertItemsEqual(['__builtins__', 'Foo'], sut.plugins.keys())
6063

6164
def test_parameters_for_constructor(self):
62-
self.plugin_file.write(
65+
self._write_file(
6366
'class Foo(object):\n'
6467
' def __init__(self, a):\n'
6568
' self.a = a'
@@ -73,7 +76,7 @@ def test_parameters_for_constructor(self):
7376
self.assertEquals(5, plugin.a)
7477

7578
def test_named_parameters_for_constructor(self):
76-
self.plugin_file.write(
79+
self._write_file(
7780
'class Foo(object):\n'
7881
' def __init__(self, a):\n'
7982
' self.a = a'
@@ -88,7 +91,7 @@ def test_named_parameters_for_constructor(self):
8891
self.assertEquals(5, plugin.a)
8992

9093
def test_two_plugins_in_a_file(self):
91-
self.plugin_file.write(
94+
self._write_file(
9295
'class Foo(object):\n'
9396
' pass\n'
9497
'class Bar(object):\n'

0 commit comments

Comments
 (0)