Ejemplo n.º 1
0
    def testUnboundMethods(self):
        """Verifies unbound method attachment to ee.Algorithms."""

        # Use a custom set of known functions.
        def MockSend(path, unused_params, unused_method=None, unused_raw=None):
            if path == '/algorithms':
                return {
                    'Foo': {
                        'type': 'Algorithm',
                        'args': [],
                        'description': '',
                        'returns': 'Object'
                    },
                    'Foo.bar': {
                        'type': 'Algorithm',
                        'args': [],
                        'description': '',
                        'returns': 'Object'
                    },
                    'Quux.baz': {
                        'type': 'Algorithm',
                        'args': [],
                        'description': '',
                        'returns': 'Object'
                    },
                    'last': {
                        'type': 'Algorithm',
                        'args': [],
                        'description': '',
                        'returns': 'Object'
                    }
                }

        ee.data.send_ = MockSend
        ee.data._use_cloud_api = False

        ee.ApiFunction.importApi(lambda: None, 'Quux', 'Quux')
        ee._InitializeUnboundMethods()

        self.assertTrue(callable(ee.Algorithms.Foo))
        self.assertTrue(callable(ee.Algorithms.Foo.bar))
        self.assertTrue('Quux' not in ee.Algorithms)
        self.assertEqual(ee.call('Foo.bar'), ee.Algorithms.Foo.bar())
        self.assertNotEqual(ee.Algorithms.Foo.bar(), ee.Algorithms.last())
Ejemplo n.º 2
0
  def testUnboundMethods(self):
    """Verifies unbound method attachment to ee.Algorithms."""

    # Use a custom set of known functions.
    def MockSend(path, unused_params, unused_method=None, unused_raw=None):
      if path == '/algorithms':
        return {
            'Foo': {
                'type': 'Algorithm',
                'args': [],
                'description': '',
                'returns': 'Object'
            },
            'Foo.bar': {
                'type': 'Algorithm',
                'args': [],
                'description': '',
                'returns': 'Object'
            },
            'Quux.baz': {
                'type': 'Algorithm',
                'args': [],
                'description': '',
                'returns': 'Object'
            },
            'last': {
                'type': 'Algorithm',
                'args': [],
                'description': '',
                'returns': 'Object'
            }
        }
    ee.data.send_ = MockSend

    ee.ApiFunction.importApi(lambda: None, 'Quux', 'Quux')
    ee._InitializeUnboundMethods()

    self.assertTrue(callable(ee.Algorithms.Foo))
    self.assertTrue(callable(ee.Algorithms.Foo.bar))
    self.assertTrue('Quux' not in ee.Algorithms)
    self.assertEquals(ee.call('Foo.bar'), ee.Algorithms.Foo.bar())
    self.assertNotEquals(ee.Algorithms.Foo.bar(), ee.Algorithms.last())
Ejemplo n.º 3
0
  def testUnboundMethods(self):
    """Verifies unbound method attachment to ee.Algorithms."""

    # Use a custom set of known functions.
    def MockAlgorithms():
      return {
          'Foo': {
              'type': 'Algorithm',
              'args': [],
              'description': '',
              'returns': 'Object'
          },
          'Foo.bar': {
              'type': 'Algorithm',
              'args': [],
              'description': '',
              'returns': 'Object'
          },
          'Quux.baz': {
              'type': 'Algorithm',
              'args': [],
              'description': '',
              'returns': 'Object'
          },
          'last': {
              'type': 'Algorithm',
              'args': [],
              'description': '',
              'returns': 'Object'
          }
      }
    ee.data.getAlgorithms = MockAlgorithms

    ee.ApiFunction.importApi(lambda: None, 'Quux', 'Quux')
    ee._InitializeUnboundMethods()

    self.assertTrue(callable(ee.Algorithms.Foo))
    self.assertTrue(callable(ee.Algorithms.Foo.bar))
    self.assertTrue('Quux' not in ee.Algorithms)
    self.assertEqual(ee.call('Foo.bar'), ee.Algorithms.Foo.bar())
    self.assertNotEqual(ee.Algorithms.Foo.bar(), ee.Algorithms.last())