def test_read_write_states(self): doc = BioDesDoc().from_xml(self.create_element()) doc.add_or_update_state(type='floruit', frm="1900", to="1910", place='Zohar', place_id='1') state = doc.get_state(type='floruit') self.assertEqual(state.get('from'), '1900') self.assertEqual(state.get('to'), '1910') self.assertEqual(state.get('type'), 'floruit') self.assertEqual(state.find('place').text, 'Zohar') self.assertEqual(state.find('place').get('key'), '1') doc.add_or_update_state(type='floruit', place_id='', place='') self.assertEqual(state.find('place').get('key'), '') states = doc.get_states(type='floruit') self.assertEqual(states, [state]) doc.add_state(type='occupation', idno="1") self.assertEqual(len(states), 1) doc.add_state(type='occupation', idno="2") doc.add_state(type='occupation', idno="3") states = doc.get_states(type='occupation') self.assertEqual(len(states), 3) doc.remove_state(type='occupation', idx=1) states = doc.get_states(type='occupation') self.assertEqual(len(states), 2) self.assertEqual([s.get('idno') for s in states], ['1', '3']) #remove states by index number states = doc.get_states() some_state = states[1] some_index = some_state.getparent().index(some_state) doc.remove_state(idx= some_index) self.assertEqual(len(states)-1, len(doc.get_states()))