<s> from __future__ import division <EOL> from vistrails . db . domain import DBActionAnnotation <EOL> import unittest <EOL> import copy <EOL> import vistrails . core <EOL> class ActionAnnotation ( DBActionAnnotation ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> DBActionAnnotation . __init__ ( self , * args , ** kwargs ) <EOL> if self . id is None : <EOL> self . id = - <NUM_LIT:1> <EOL> def __copy__ ( self ) : <EOL> return ActionAnnotation . do_copy ( self ) <EOL> def do_copy ( self , new_ids = False , id_scope = None , id_remap = None ) : <EOL> cp = DBActionAnnotation . do_copy ( self , new_ids , id_scope , id_remap ) <EOL> cp . __class__ = ActionAnnotation <EOL> return cp <EOL> @ staticmethod <EOL> def convert ( _annotation ) : <EOL> _annotation . __class__ = ActionAnnotation <EOL> id = DBActionAnnotation . db_id <EOL> key = DBActionAnnotation . db_key <EOL> value = DBActionAnnotation . db_value <EOL> action_id = DBActionAnnotation . db_action_id <EOL> date = DBActionAnnotation . db_date <EOL> user = DBActionAnnotation . db_user <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> rep = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return rep % ( str ( self . id ) , str ( self . action_id ) , str ( self . key ) , <EOL> str ( self . value ) , str ( self . date ) , str ( self . user ) ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if type ( self ) != type ( other ) : <EOL> return False <EOL> if self . key != other . key : <EOL> return False <EOL> if self . value != other . value : <EOL> return False <EOL> if self . action_id != other . action_id : <EOL> return False <EOL> return True <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> class TestActionAnnotation ( unittest . TestCase ) : <EOL> def create_annotation ( self , id_scope = None ) : <EOL> from vistrails . db . domain import IdScope <EOL> if id_scope is None : <EOL> id_scope = IdScope ( ) <EOL> annotation = ActionAnnotation ( id = id_scope . getNewId ( ActionAnnotation . vtType ) , <EOL> key = '<STR_LIT>' , action_id = <NUM_LIT:1> L , <EOL> value = '<STR_LIT>' , user = '<STR_LIT:test>' ) <EOL> return annotation <EOL> def test_copy ( self ) : <EOL> from vistrails . db . domain import IdScope <EOL> id_scope = IdScope ( ) <EOL> a1 = self . create_annotation ( id_scope ) <EOL> a2 = copy . copy ( a1 ) <EOL> self . assertEquals ( a1 , a2 ) <EOL> self . assertEquals ( a1 . id , a2 . id ) <EOL> a3 = a1 . do_copy ( True , id_scope , { } ) <EOL> self . assertEquals ( a1 , a3 ) <EOL> self . assertNotEquals ( a1 . id , a3 . id ) <EOL> def test_serialization ( self ) : <EOL> import vistrails . core . db . io <EOL> a1 = self . create_annotation ( ) <EOL> xml_str = vistrails . core . db . io . serialize ( a1 ) <EOL> a2 = vistrails . core . db . io . unserialize ( xml_str , ActionAnnotation ) <EOL> self . assertEquals ( a1 , a2 ) <EOL> self . assertEquals ( a1 . id , a2 . id ) <EOL> def test_str ( self ) : <EOL> a1 = self . create_annotation ( ) <EOL> str ( a1 ) </s>
