當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。