Beispiel #1
0
  def testDictionary(self):
    """Verifies basic behavior of ee.Dictionary."""
    src = {'a': 1, 'b': 2, 'c': 'three'}
    dictionary = ee.Dictionary(src)
    self.assertEqual({
        'type': 'Dictionary',
        'value': src
    },
                     ee.Serializer(False)._encode(dictionary))
    self.assertEqual({'constantValue': {
        'a': 1,
        'b': 2,
        'c': 'three'
    }},
                     ee.Serializer(False,
                                   for_cloud_api=True)._encode(dictionary))

    f = ee.Feature(None, {'properties': src})
    computed = ee.Dictionary(f.get('properties'))
    self.assertIsInstance(computed, ee.Dictionary)

    # The 4 types of arguments we expect
    cons = (ee.Dictionary(src),
            ee.Dictionary(f.get('properties')),
            ee.Dictionary(),
            ee.Dictionary(('one', 1)))

    for d in cons:
      self.assertIsInstance(d, ee.ComputedObject)
Beispiel #2
0
  def testList(self):
    """Verifies basic behavior of ee.List."""
    l = ee.List([1, 2, 3])
    self.assertEquals([1, 2, 3], ee.Serializer(False)._encode(l))

    computed = ee.List([1, 2, 3]).slice(0)    # pylint: disable=no-member
    self.assertTrue(isinstance(computed, ee.List))
    self.assertEquals(ee.ApiFunction.lookup('List.slice'), computed.func)
    self.assertEquals({'list': ee.List([1, 2, 3]), 'start': ee.Number(0)},
                      computed.args)
    def testDictionary(self):
        """Verifies basic behavior of ee.Dictionary."""
        src = {'a': 1, 'b': 2, 'c': 'three'}
        dictionary = ee.Dictionary(src)
        self.assertEquals({
            'type': 'Dictionary',
            'value': src
        },
                          ee.Serializer(False)._encode(dictionary))

        f = ee.Feature(None, {'properties': src})
        computed = ee.Dictionary(f.get('properties'))
        self.assertTrue(isinstance(computed, ee.Dictionary))

        try:
            ee.Dictionary(1)
        except ee.EEException as e:
            self.assertTrue('Invalid argument' in str(e))
        else:
            self.fail('Expected an exception.')