Beispiel #1
0
    def testMockupBraveNewAccess(self):
        with self.assertRaises(ValueError) as context:
            get_config_attribute('KONFIG.nim.nosuchnumber', self.config_obj)

        self.assertTrue(
            "Head is 'KONFIG', expected 'config'" in str(context.exception))

        self.assertTrue(
            get_config_attribute('config.bla.test', self.config_obj))
        self.assertTrue(
            get_config_attribute('config.nim[0].bla', self.config_obj))
        self.assertTrue(
            get_config_attribute('config.nim[1].bla', self.config_obj))
        self.assertTrue(
            get_config_attribute('config.nim[1].blub', self.config_obj))
        self.assertEqual(
            2, len(get_config_attribute('config.nim', self.config_obj)))
        self.assertTrue(
            get_config_attribute("config.arg['Hello']", self.config_obj))
        self.assertEqual(
            KEY_RIGHT,
            get_config_attribute("config.arg['Hello']",
                                 self.config_obj).handleKey(KEY_RIGHT))

        with self.assertRaises(AttributeError) as context:
            get_config_attribute('config.hats.net', self.config_obj)
        self.assertTrue("'ConfigObjectMockup' object has no attribute 'hats'"
                        in str(context.exception))

        with self.assertRaises(IndexError) as context:
            get_config_attribute('config.nim[2].bla', self.config_obj)
        self.assertTrue("list index out of range" in str(context.exception))

        with self.assertRaises(AttributeError) as context:
            get_config_attribute('config.nim.nosuchnumber', self.config_obj)
        self.assertTrue("'list' object has no attribute 'nosuchnumber'" in str(
            context.exception))
	def testMockupBraveNewAccess(self):
		with self.assertRaises(ValueError) as context:
			get_config_attribute('KONFIG.nim.nosuchnumber', self.config_obj)

		self.assertTrue(
			"Head is 'KONFIG', expected 'config'" in context.exception)

		self.assertTrue(
			get_config_attribute('config.bla.test', self.config_obj))
		self.assertTrue(
			get_config_attribute('config.nim[0].bla', self.config_obj))
		self.assertTrue(
			get_config_attribute('config.nim[1].bla', self.config_obj))
		self.assertTrue(
			get_config_attribute('config.nim[1].blub', self.config_obj))
		self.assertEqual(
			2,
			len(get_config_attribute('config.nim', self.config_obj)))
		self.assertTrue(
			get_config_attribute("config.arg['Hello']", self.config_obj))
		self.assertEqual(
			KEY_RIGHT,
			get_config_attribute(
				"config.arg['Hello']",
				self.config_obj).handleKey(KEY_RIGHT))

		with self.assertRaises(AttributeError) as context:
			get_config_attribute('config.hats.net', self.config_obj)
		self.assertTrue(
			"'ConfigObjectMockup' object has no attribute 'hats'" in context.exception)

		with self.assertRaises(IndexError) as context:
			get_config_attribute('config.nim[2].bla', self.config_obj)
		self.assertTrue("list index out of range" in context.exception)

		with self.assertRaises(AttributeError) as context:
			get_config_attribute('config.nim.nosuchnumber', self.config_obj)
		self.assertTrue(
			"'list' object has no attribute 'nosuchnumber'" in context.exception)
Beispiel #3
0
    def testBraveNewSanitation(self):
        with self.assertRaises(ValueError) as context:
            get_config_attribute(SOME_BAD_KEY, self.config_obj)
        self.assertTrue('private member' in str(context.exception))

        with self.assertRaises(ValueError) as context:
            get_config_attribute('__class__', self.config_obj)
        self.assertTrue('Invalid path length' in str(context.exception))

        with self.assertRaises(ValueError) as context:
            get_config_attribute('config.__class__..', self.config_obj)
        self.assertTrue('private member' in str(context.exception))

        with self.assertRaises(ValueError) as context:
            get_config_attribute('config.nim.__class__.__name__',
                                 self.config_obj)
        self.assertTrue('private member' in str(context.exception))

        with self.assertRaises(ValueError) as context:
            get_config_attribute('config.nim................', self.config_obj)
        self.assertTrue('empty attr_name' in str(context.exception))

        with self.assertRaises(AttributeError) as context:
            get_config_attribute('config.nim', None)
        self.assertTrue("'NoneType' object has no attribute 'nim'" in str(
            context.exception))
	def testBraveNewSanitation(self):
		with self.assertRaises(ValueError) as context:
			get_config_attribute(SOME_BAD_KEY, self.config_obj)
		self.assertTrue('private member' in context.exception)

		with self.assertRaises(ValueError) as context:
			get_config_attribute('__class__', self.config_obj)
		self.assertTrue('Invalid path length' in context.exception)

		with self.assertRaises(ValueError) as context:
			get_config_attribute('config.__class__..', self.config_obj)
		self.assertTrue('private member' in context.exception)

		with self.assertRaises(ValueError) as context:
			get_config_attribute('config.nim.__class__.__name__',
								 self.config_obj)
		self.assertTrue('private member' in context.exception)

		with self.assertRaises(ValueError) as context:
			get_config_attribute('config.nim................', self.config_obj)
		self.assertTrue('empty attr_name' in context.exception)

		with self.assertRaises(AttributeError) as context:
			get_config_attribute('config.nim', None)
		self.assertTrue(
			"'NoneType' object has no attribute 'nim'" in context.exception)