Merge lp:~james-page/charm-helpers/cleanup_flake8 into lp:charm-helpers

Proposed by James Page
Status: Merged
Approved by: Adam Gandelman
Approved revision: 48
Merged at revision: 54
Proposed branch: lp:~james-page/charm-helpers/cleanup_flake8
Merge into: lp:charm-helpers
Diff against target: 138 lines (+20/-20)
3 files modified
charmhelpers/core/hookenv.py (+1/-0)
tests/core/test_hookenv.py (+14/-13)
tests/payload/test_execd.py (+5/-7)
To merge this branch: bzr merge lp:~james-page/charm-helpers/cleanup_flake8
Reviewer Review Type Date Requested Status
Charm Helper Maintainers Pending
Review via email: mp+174129@code.launchpad.net

Description of the change

Tidy flake8 warnings from core packages and associated tests.

These where annoying me on every review I did so I fixed them up.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/core/hookenv.py'
--- charmhelpers/core/hookenv.py 2013-07-05 18:22:23 +0000
+++ charmhelpers/core/hookenv.py 2013-07-11 08:33:31 +0000
@@ -335,5 +335,6 @@
335 return decorated335 return decorated
336 return wrapper336 return wrapper
337337
338
338def charm_dir():339def charm_dir():
339 return os.environ.get('CHARM_DIR')340 return os.environ.get('CHARM_DIR')
340341
=== modified file 'tests/core/test_hookenv.py'
--- tests/core/test_hookenv.py 2013-07-05 18:43:41 +0000
+++ tests/core/test_hookenv.py 2013-07-11 08:33:31 +0000
@@ -445,7 +445,7 @@
445 def test_gets_relations(self, relation_get, related_units,445 def test_gets_relations(self, relation_get, related_units,
446 relation_ids, relation_types, local_unit):446 relation_ids, relation_types, local_unit):
447 local_unit.return_value = 'u0'447 local_unit.return_value = 'u0'
448 relation_types.return_value = ['t1','t2']448 relation_types.return_value = ['t1', 't2']
449 relation_ids.return_value = ['i1']449 relation_ids.return_value = ['i1']
450 related_units.return_value = ['u1', 'u2']450 related_units.return_value = ['u1', 'u2']
451 relation_get.return_value = {'key': 'val'}451 relation_get.return_value = {'key': 'val'}
@@ -507,8 +507,8 @@
507 @patch('charmhelpers.core.hookenv.relation_get')507 @patch('charmhelpers.core.hookenv.relation_get')
508 @patch('charmhelpers.core.hookenv.os')508 @patch('charmhelpers.core.hookenv.os')
509 def test_gets_execution_environment_no_relation(509 def test_gets_execution_environment_no_relation(
510 self, os_, relations_get, relations, relation_id,510 self, os_, relations_get, relations, relation_id,
511 local_unit, relation_type, config):511 local_unit, relation_type, config):
512 config.return_value = 'some-config'512 config.return_value = 'some-config'
513 relation_type.return_value = 'some-type'513 relation_type.return_value = 'some-type'
514 local_unit.return_value = 'some-unit'514 local_unit.return_value = 'some-unit'
@@ -526,7 +526,6 @@
526 'env': 'some-environment',526 'env': 'some-environment',
527 })527 })
528528
529
530 @patch('charmhelpers.core.hookenv.os')529 @patch('charmhelpers.core.hookenv.os')
531 def test_gets_the_relation_id(self, os_):530 def test_gets_the_relation_id(self, os_):
532 os_.environ = {531 os_.environ = {
@@ -618,7 +617,7 @@
618 def test_sets_relation_with_relation_id(self, check_call_):617 def test_sets_relation_with_relation_id(self, check_call_):
619 hookenv.relation_set(relation_id="foo", bar="baz")618 hookenv.relation_set(relation_id="foo", bar="baz")
620 check_call_.assert_called_with(['relation-set', '-r', 'foo',619 check_call_.assert_called_with(['relation-set', '-r', 'foo',
621 'bar=baz'])620 'bar=baz'])
622621
623 @patch('subprocess.check_call')622 @patch('subprocess.check_call')
624 def test_sets_relation_with_missing_value(self, check_call_):623 def test_sets_relation_with_missing_value(self, check_call_):
@@ -639,10 +638,11 @@
639 hookenv.open_port(443, "TCP")638 hookenv.open_port(443, "TCP")
640 hookenv.open_port(80)639 hookenv.open_port(80)
641 hookenv.open_port(100, "UDP")640 hookenv.open_port(100, "UDP")
642 calls = [call(['open-port', '443/TCP']),641 calls = [
643 call(['open-port', '80/TCP']),642 call(['open-port', '443/TCP']),
644 call(['open-port', '100/UDP']),643 call(['open-port', '80/TCP']),
645 ]644 call(['open-port', '100/UDP']),
645 ]
646 check_call_.assert_has_calls(calls)646 check_call_.assert_has_calls(calls)
647647
648 @patch('subprocess.check_call')648 @patch('subprocess.check_call')
@@ -650,10 +650,11 @@
650 hookenv.close_port(443, "TCP")650 hookenv.close_port(443, "TCP")
651 hookenv.close_port(80)651 hookenv.close_port(80)
652 hookenv.close_port(100, "UDP")652 hookenv.close_port(100, "UDP")
653 calls = [call(['close-port', '443/TCP']),653 calls = [
654 call(['close-port', '80/TCP']),654 call(['close-port', '443/TCP']),
655 call(['close-port', '100/UDP']),655 call(['close-port', '80/TCP']),
656 ]656 call(['close-port', '100/UDP']),
657 ]
657 check_call_.assert_has_calls(calls)658 check_call_.assert_has_calls(calls)
658659
659 @patch('subprocess.check_output')660 @patch('subprocess.check_output')
660661
=== modified file 'tests/payload/test_execd.py'
--- tests/payload/test_execd.py 2013-06-11 14:15:03 +0000
+++ tests/payload/test_execd.py 2013-07-11 08:33:31 +0000
@@ -18,7 +18,7 @@
18 self.test_charm_dir = charm_dir18 self.test_charm_dir = charm_dir
1919
20 env_patcher = patch.dict('os.environ',20 env_patcher = patch.dict('os.environ',
21 {'CHARM_DIR': self.test_charm_dir})21 {'CHARM_DIR': self.test_charm_dir})
22 env_patcher.start()22 env_patcher.start()
23 self.addCleanup(env_patcher.stop)23 self.addCleanup(env_patcher.stop)
2424
@@ -31,11 +31,11 @@
31 def make_preinstall_executable(self, module_dir, execd_dir='exec.d',31 def make_preinstall_executable(self, module_dir, execd_dir='exec.d',
32 error_on_preinstall=False):32 error_on_preinstall=False):
33 """Add a charm-pre-install to module dir.33 """Add a charm-pre-install to module dir.
34 34
35 When executed, the charm-pre-install will create a second35 When executed, the charm-pre-install will create a second
36 file in the same directory, charm-pre-install-success.36 file in the same directory, charm-pre-install-success.
37 """37 """
38 module_path = os.path.join(self.test_charm_dir, execd_dir, module_dir) 38 module_path = os.path.join(self.test_charm_dir, execd_dir, module_dir)
39 os.makedirs(module_path)39 os.makedirs(module_path)
4040
41 charm_pre_install_path = os.path.join(module_path,41 charm_pre_install_path = os.path.join(module_path,
@@ -44,7 +44,7 @@
44 'charm-pre-install-success')44 'charm-pre-install-success')
45 with open(charm_pre_install_path, 'w+') as f:45 with open(charm_pre_install_path, 'w+') as f:
46 f.write("#!/bin/bash\n"46 f.write("#!/bin/bash\n"
47 "/usr/bin/touch {}".format(pre_install_success_path))47 "/usr/bin/touch {}".format(pre_install_success_path))
48 perms = stat.S_IXUSR48 perms = stat.S_IXUSR
49 # If the charm-pre-install should run without errors,49 # If the charm-pre-install should run without errors,
50 # ensure it is executable.50 # ensure it is executable.
@@ -113,7 +113,6 @@
113 'charm-pre-install') for mod in modules]113 'charm-pre-install') for mod in modules]
114 self.assertItemsEqual(submodules, expected)114 self.assertItemsEqual(submodules, expected)
115115
116
117 def test_execd_run(self):116 def test_execd_run(self):
118 modules = ['basenode', 'mod2', 'c']117 modules = ['basenode', 'mod2', 'c']
119 for module in modules:118 for module in modules:
@@ -138,10 +137,9 @@
138 self.test_charm_dir))137 self.test_charm_dir))
139 log_.assert_called_with(expected_log)138 log_.assert_called_with(expected_log)
140139
141
142 @patch('charmhelpers.core.hookenv.log')140 @patch('charmhelpers.core.hookenv.log')
143 @patch('sys.exit')141 @patch('sys.exit')
144 def test_execd_run_dies_with_return_code(self, exit_, log_):142 def test_execd_run_dies_with_return_code(self, exit_, log):
145 self.make_preinstall_executable(module_dir='basenode',143 self.make_preinstall_executable(module_dir='basenode',
146 error_on_preinstall=True)144 error_on_preinstall=True)
147145

Subscribers

People subscribed via source and target branches