Although other imports in the file don't follow this, we should only be importing modules, not classes. So technically this should be just "import StringIO"
44 + 'injected': 1}
Minor nitpick, this indent should be consistent with the others.
116 + except_msg = "Test failed with an unknown exception"
This is an interesting strategy, but I would suggest when something happens and you don't know what went wrong to just do a self.fail(error_message), where 'error_message' is the exception contents. Just saying "unknown exception" isn't very helpful when trying to debug, but the failure message will help out greatly.
Would give the reason, while still making sure the test failed.
Lines 300 - 307, you shouldn't need those backslashes and if you could, where applicable, line up parameters under the space after the method's opening "(" like this:
As a general comment, if you find yourself repeating test "setup", such as creating a connection and setting some test parameters, you might consider breaking similar tests into their own TestCase classes and putting the common code in setUp().
I'm going to keep looking at this, as it's a good number of tests...but hopefully this will kick off some discussion.
22 +from StringIO import StringIO
Although other imports in the file don't follow this, we should only be importing modules, not classes. So technically this should be just "import StringIO"
44 + 'injected': 1}
Minor nitpick, this indent should be consistent with the others.
116 + except_msg = "Test failed with an unknown exception"
This is an interesting strategy, but I would suggest when something happens and you don't know what went wrong to just do a self.fail( error_message) , where 'error_message' is the exception contents. Just saying "unknown exception" isn't very helpful when trying to debug, but the failure message will help out greatly.
For example:
524 + try: instance, network_info) e(fail, msg=self. except_ msg)
525 + conn.spawn(
526 + except Exception, e:
527 + fail = 1
528 + time.sleep(1)
529 +
530 + self.assertFals
Would give me a generic failure message, but:
524 + try: instance, network_info)
525 + conn.spawn(
526 + except Exception as err:
527 + self.fail(err)
Would give the reason, while still making sure the test failed.
Lines 300 - 307, you shouldn't need those backslashes and if you could, where applicable, line up parameters under the space after the method's opening "(" like this:
300 + conn.firewall_ driver. setattr( 'setup_ basic_filtering ',
301 + self.fake_none)
In all of the tests, FLAGS are auto-magically reset, so feel free to just edit them directly:
348 + fake_flag = 'VIR_MIGRATE_ UNDEFINE_ SOURCE, VIR_MIGRATE_ PEER2PEER' StubOutWithMock (connection. FLAGS, 'live_migration _flag') FLAGS.live_ migration_ flag = fake_flag
349 + self.mox.
350 + connection.
Could safely become:
348 + migration_flag = 'VIR_MIGRATE_ UNDEFINE_ SOURCE, VIR_MIGRATE_ PEER2PEER' migration_ flag = migration_flag
349 + FLAGS.live_
There are existing structures for Mocks and Stubs, so this:
451 + self.mox. StubOutWithMock (connection. LibvirtConnecti on, 'get_info') LibvirtConnecti on.get_ info = fake_get_info
452 + connection.
could just be:
451 + self.stubs. Set(connection. LibvirtConnecti on, 'get_info', fake_get_info)
if you wanted to do it in a single line.
As a general comment, if you find yourself repeating test "setup", such as creating a connection and setting some test parameters, you might consider breaking similar tests into their own TestCase classes and putting the common code in setUp().
I'm going to keep looking at this, as it's a good number of tests...but hopefully this will kick off some discussion.
Thanks for the tests!