Commits

Johannes Kolb committed 7cd00fa

make all simple attributes of osm.object writeable

  • Participants
  • Parent commits f1aac02

Comments (0)

Files changed (3)

osmium/osm_objects.pxi

 
 # Define the basic OSM objects
 
+from c_osmium.osm cimport osm_object_id_t, osm_version_t, osm_changeset_id_t, osm_user_id_t, time_t
+from libcpp cimport bool
+
 cdef class Object:
     """Base class for OSM objects
     
             return _getOsmObject(self.c_object).id_()
         def __set__(self, osm_object_id_t val):
             _getOsmObject(self.c_object).id_(val)
+
     property version:
         def __get__(self):
             return _getOsmObject(self.c_object).version()
         def __set__(self, osm_version_t val):
             _getOsmObject(self.c_object).version(val)
+
     property changeset:
         def __get__(self):
             return _getOsmObject(self.c_object).changeset()
+        def __set__(self, osm_changeset_id_t val):
+            _getOsmObject(self.c_object).changeset(val)
+
     property uid:
         def __get__(self):
             return _getOsmObject(self.c_object).uid()
+        def __set__(self, osm_user_id_t val):
+            _getOsmObject(self.c_object).uid(val)
+
     property timestamp:
         def __get__(self):
             return _getOsmObject(self.c_object).timestamp()
+        def __set__(self, time_t val):
+            _getOsmObject(self.c_object).timestamp(val)
+
     property endtime:
         def __get__(self):
             return _getOsmObject(self.c_object).endtime()
+        def __set__(self, time_t val):
+            _getOsmObject(self.c_object).endtime(val)
+
     property user:
         def __get__(self):
             return (<char*>_getOsmObject(self.c_object).user()).decode('utf-8')
+        def __set__(self, str val):
+            cdef bytes encoded_val
+            encoded_val = val.encode('utf-8')
+            _getOsmObject(self.c_object).user(encoded_val)
+
     property visible:
         def __get__(self):
             return _getOsmObject(self.c_object).visible()
+        def __set__(self, bool val):
+            _getOsmObject(self.c_object).visible(val)
+
     property tags:
         def __get__(self):
             global _cache_taglist

tests/test_osm.py

         self.assertAlmostEqual(keeper.meta.bounds.top,     0.0153163)
         self.assertAlmostEqual(keeper.meta.bounds.right,  -0.0032339)
 
-class OSMObject(TestCase):
-    def setUp(self):
-        # use Node as example object
-        self.obj = osmium.osm.Node()
-
-    def test_constructor_ifCalled_raisesException(self):
-        with self.assertRaises(TypeError):
-            result = osmium.osm.Object()
-
-    def test_idProperty_isWriteable(self):
-        some_id = 12
-        self.obj.id_ = some_id
-        self.assertEquals(some_id, self.obj.id_)
-

tests/test_writeable_objects.py

+from unittest import TestCase
+
+import osmium
+
+class OSMObject(TestCase):
+    def setUp(self):
+        # use Node as example object
+        self.obj = osmium.osm.Node()
+
+    def test_constructor_ifCalled_raisesException(self):
+        with self.assertRaises(TypeError):
+            result = osmium.osm.Object()
+
+    def test_idProperty_isWriteable(self):
+        some_id = 12
+        self.obj.id_ = some_id
+        self.assertEquals(some_id, self.obj.id_)
+
+    def test_simpleProperties_areWriteable(self):
+        attributes = {
+                "id_": 12,
+                "version": 1,
+                "changeset": 43,
+                "uid": 42,
+                "timestamp": 34823762,
+                "endtime": 0,
+                "user": "IUser",
+                "visible": True,
+                }
+
+        for key in attributes:
+            setattr(self.obj, key, attributes[key])
+
+        for key in attributes:
+            self.assertEquals(getattr(self.obj, key), attributes[key])
+