)]}'
{"playbooks/inventory/dynamic_inventory.py":[{"author":{"_account_id":12000,"name":"Ian Cordasco","email":"sigmavirus24@gmail.com","username":"sigmavirus24"},"change_message_id":"c9ecab7b47036c614714985a0f1b5f68c92349ef","unresolved":false,"context_lines":[{"line_number":1052,"context_line":"        )"},{"line_number":1053,"context_line":"    return user_defined_config"},{"line_number":1054,"context_line":""},{"line_number":1055,"context_line":""},{"line_number":1056,"context_line":"def make_backup(config_path, inventory_file_path):"},{"line_number":1057,"context_line":"    # Create a backup of all previous inventory files as a tar archive"},{"line_number":1058,"context_line":"    inventory_backup_file \u003d os.path.join("}],"source_content_type":"text/x-python","patch_set":1,"id":"9abb7d3a_76377db0","line":1055,"updated":"2016-06-03 18:23:38.000000000","message":"+100 on this refactor. This should make things significantly easier for you to test in the future.","commit_id":"543ec0173308cf33404907e395005effd236291c"}],"tests/test_inventory.py":[{"author":{"_account_id":12000,"name":"Ian Cordasco","email":"sigmavirus24@gmail.com","username":"sigmavirus24"},"change_message_id":"c9ecab7b47036c614714985a0f1b5f68c92349ef","unresolved":false,"context_lines":[{"line_number":644,"context_line":""},{"line_number":645,"context_line":""},{"line_number":646,"context_line":"class TestMultipleRuns(unittest.TestCase):"},{"line_number":647,"context_line":"    def test_creating_backup_file(self):"},{"line_number":648,"context_line":"        inventory_file_path \u003d os.path.join(TARGET_DIR,"},{"line_number":649,"context_line":"                                           \u0027openstack_inventory.json\u0027)"},{"line_number":650,"context_line":"        get_backup_name_path \u003d \u0027dynamic_inventory.get_backup_name\u0027"}],"source_content_type":"text/x-python","patch_set":1,"id":"9abb7d3a_563a3999","line":647,"updated":"2016-06-03 18:23:38.000000000","message":"So I tend to build this up differently for the mock when I\u0027m doing mocking that is this intense. Since you have a file object that\u0027s going to act as a context-manager, you can do this:\n\n    tar_file \u003d mock.Mock()\n    tar_file.__enter__.return_value \u003d tar_file\n\nThen do\n\n    with mock.patch(\u0027dynamic_inventory.tarfile.open\u0027) as tar_open:\n        tar_open.return_value \u003d tar_file\n        with mock.patch(get_backup_name_path) as backup_mock:\n            # ...\n\nThen\n\n    tar_open.assert_called_once_with(backup_path, \u0027a\u0027)\n    tar_file.add.assert_called_once_with(...)\n\nThat should make things more self-explanatory and simpler since you now have two well named mocks to use.","commit_id":"543ec0173308cf33404907e395005effd236291c"},{"author":{"_account_id":12892,"name":"Nolan Brubaker","email":"nolan.brubaker@rackspace.com","username":"nrb"},"change_message_id":"bf81dfc3f5ef99c555597c4f46cd86cfc9ced3de","unresolved":false,"context_lines":[{"line_number":644,"context_line":""},{"line_number":645,"context_line":""},{"line_number":646,"context_line":"class TestMultipleRuns(unittest.TestCase):"},{"line_number":647,"context_line":"    def test_creating_backup_file(self):"},{"line_number":648,"context_line":"        inventory_file_path \u003d os.path.join(TARGET_DIR,"},{"line_number":649,"context_line":"                                           \u0027openstack_inventory.json\u0027)"},{"line_number":650,"context_line":"        get_backup_name_path \u003d \u0027dynamic_inventory.get_backup_name\u0027"}],"source_content_type":"text/x-python","patch_set":1,"id":"9abb7d3a_359e8ab8","line":647,"in_reply_to":"9abb7d3a_563a3999","updated":"2016-06-03 18:55:59.000000000","message":"Great, thanks! That definitely looks easier to use, rather than reaching into the internals of the mock objects after-the fact.","commit_id":"543ec0173308cf33404907e395005effd236291c"}]}
