当前位置: 首页>>代码示例>>Python>>正文


Python Dependency.__getattribute__方法代码示例

本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.__getattribute__方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.__getattribute__方法的具体用法?Python Dependency.__getattribute__怎么用?Python Dependency.__getattribute__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.utilities.inversion_of_control.Dependency的用法示例。


在下文中一共展示了Dependency.__getattribute__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SpotInstanceCheckTests

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import __getattribute__ [as 别名]
class SpotInstanceCheckTests(unittest.TestCase):
    def setUp(self):
        # set up mocks
        register_mock_dependencies()
        self.cloud_provider = Dependency("CloudProvider").value
        self.file_provider = Dependency("FileProvider").value
        self.email_provider = Dependency("EmailProvider").value

        # logger
        logger = Dependency("SimpleConsole").value

        # set up mongo deployer
        self.spot_checker = SpotInstanceChecker(logger)
        self.spot_checker.request_headers = [('id', 'idy'), ('chicken', 'SuperChicken'), ('danger', 'WhoKilledKenny')]
        self.spot_checker.launch_spec_headers = [('rocket', 'RocketMan')]
        self.spot_checker.status_headers = [('code', "StatusCode")]
        self.spot_checker.headers = list(itertools.chain(*[['*', 'Instance Tag'],
                                                           [h[1] for h in self.spot_checker.request_headers],
                                                           [h[1] for h in self.spot_checker.launch_spec_headers],
                                                           [h[1] for h in self.spot_checker.status_headers]]))


    def tearDown(self):
        # remove dependencies for next set of tests
        dependencies.clear()


    def test_check_spot_instances(self):
        # expected perfect match
        retrieved_spot_instances = [PretendSpotInstanceObject("id1"), PretendSpotInstanceObject("id2")]
        self.cloud_provider.current_spot_instances = retrieved_spot_instances

        # expected (from file record)
        self.file_provider.file_lines = {'id1': {'chicken': 'woot', 'id': 'id1', 'danger': 'zone', 'launch_specification':{'rocket':'go'}, 'status':{'code':'bar'}},
                                         'id2': {'chicken': 'woot', 'id': 'id2', 'danger': 'zone', 'launch_specification':{'rocket':'go'}, 'status':{'code':'bar'}}}

        # go
        self.spot_checker.do_comparison()

        self.assertEqual(self.spot_checker.current, self.spot_checker.recorded)
        self.assertFalse(hasattr(self.spot_checker.current["id1"]["status"], "update_time"))
        self.assertFalse(hasattr(self.spot_checker.current["id2"]["status"], "update_time"))
        self.assertFalse(hasattr(self.spot_checker, 'diff'))

        # File provider assertions
        self.assertIn(self.spot_checker.current_file_path, self.file_provider.files.keys())
        self.assertEqual([self.spot_checker.current_file_path], self.file_provider.deleted_files)

        # Email provider assertions - EVERYTHING should be None
        for attr in self.email_provider.__dict__.keys():
            self.assertIsNone(self.email_provider.__getattribute__(attr))


    def test_check_spot_one_missing(self):
        expected_diff = {'*': '-', 'RocketMan': 'fuel', 'SuperChicken': 'parrot', 'WhoKilledKenny': 'manger', 'idy': 'id2', 'StatusCode': 'bar'}
        retrieved_spot_instances = [PretendSpotInstanceObject("id1")]
        self.cloud_provider.current_spot_instances = retrieved_spot_instances

        # expected (from file record)
        self.file_provider.file_lines = {'id1': {'chicken': 'woot', 'id': 'id1', 'danger': 'zone', 'launch_specification':{'rocket':'go'}, 'status':{'code':'bar'}},
                                         'id2': {'chicken': 'parrot', 'id': 'id2', 'danger': 'manger', 'launch_specification':{'rocket':'fuel'}, 'status':{'code':'bar'}}}

        # go
        self.spot_checker.do_comparison()

        self.assertEqual(self.spot_checker.current["id1"], self.spot_checker.recorded["id1"])
        self.assertFalse(hasattr(self.spot_checker.current, "id2"))
        self.assertEqual(self.spot_checker.changes, {'removed': ['id2'], 'modified': [], 'added': []})
        self.assertDictEqual(self.spot_checker.diff[0], expected_diff)

        # File provider assertions
        self.assertEqual([self.spot_checker.recorded_file_path], self.file_provider.deleted_files)
        self.assertEqual([(self.spot_checker.current_file_path, self.spot_checker.recorded_file_path)], self.file_provider.moved_files)

        # Email provider assertions
        self.assertEqual(self.email_provider.html_from_email, '[email protected]')
        self.assertEqual(self.email_provider.html_subject, 'Spot Instance Monitor')
        email_terms = ['SuperChicken', 'WhoKilledKenny', 'RocketMan', 'parrot', 'manger', 'fuel']
        for value in email_terms:
            self.assertIn(value, self.email_provider.html_message)



    def test_check_spot_one_extra(self):
        expected_diff = {'*': '+', 'RocketMan': 'go', 'SuperChicken': 'woot', 'WhoKilledKenny': 'zone', 'idy': 'id2', 'StatusCode': 'bar'}
        retrieved_spot_instances = [PretendSpotInstanceObject("id1"), PretendSpotInstanceObject("id2")]
        self.cloud_provider.current_spot_instances = retrieved_spot_instances

        # expected (from file record)
        self.file_provider.file_lines = {'id1': {'chicken': 'woot', 'id': 'id1', 'danger': 'zone', 'launch_specification':{'rocket':'go'}, 'status':{'code':'bar'}}}

        # go
        self.spot_checker.do_comparison()

        self.assertEqual(self.spot_checker.current["id1"], self.spot_checker.recorded["id1"])
        self.assertFalse(hasattr(self.spot_checker.recorded, "id2"))
        self.assertEqual(self.spot_checker.changes, {'removed': [], 'modified': [], 'added': ['id2']})
        self.assertDictEqual(self.spot_checker.diff[0], expected_diff)

        # File provider assertions
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:test_spot_instance_check.py


注:本文中的common.utilities.inversion_of_control.Dependency.__getattribute__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。