<s> import unittest <EOL> try : <EOL> import StringIO as io <EOL> except ImportError : <EOL> import io <EOL> import re <EOL> from resync . resource import Resource <EOL> from resync . change_list import ChangeList <EOL> from resync . resource_list import ResourceList <EOL> from resync . sitemap import SitemapParseError <EOL> class TestChangeList ( unittest . TestCase ) : <EOL> def test1_set_with_repeats ( self ) : <EOL> src = ChangeList ( ) <EOL> src . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:c>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:2> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:2> , change = '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( src ) , <NUM_LIT:5> , "<STR_LIT>" ) <EOL> def test2_with_repeats_again ( self ) : <EOL> r1 = Resource ( uri = '<STR_LIT:a>' , length = <NUM_LIT:1> , change = '<STR_LIT>' ) <EOL> r2 = Resource ( uri = '<STR_LIT:b>' , length = <NUM_LIT:2> , change = '<STR_LIT>' ) <EOL> i = ChangeList ( ) <EOL> i . add ( r1 ) <EOL> i . add ( r2 ) <EOL> self . assertEqual ( len ( i ) , <NUM_LIT:2> ) <EOL> r1d = Resource ( uri = '<STR_LIT:a>' , length = <NUM_LIT:10> , change = '<STR_LIT>' ) <EOL> i . add ( r1d ) <EOL> self . assertEqual ( len ( i ) , <NUM_LIT:3> ) <EOL> def test3_change_list ( self ) : <EOL> src = ChangeList ( ) <EOL> src . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:2> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:c>' , timestamp = <NUM_LIT:3> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:d>' , timestamp = <NUM_LIT:4> , change = '<STR_LIT>' ) ) <EOL> src . add ( Resource ( '<STR_LIT:e>' , timestamp = <NUM_LIT:5> , change = '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( src ) , <NUM_LIT:5> , "<STR_LIT>" ) <EOL> def test4_iter ( self ) : <EOL> i = ChangeList ( ) <EOL> i . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> i . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:2> , change = '<STR_LIT>' ) ) <EOL> i . add ( Resource ( '<STR_LIT:c>' , timestamp = <NUM_LIT:3> , change = '<STR_LIT>' ) ) <EOL> i . add ( Resource ( '<STR_LIT:d>' , timestamp = <NUM_LIT:4> , change = '<STR_LIT>' ) ) <EOL> resources = [ ] <EOL> for r in i : <EOL> resources . append ( r ) <EOL> self . assertEqual ( len ( resources ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( resources [ <NUM_LIT:0> ] . uri , '<STR_LIT:a>' ) <EOL> self . assertEqual ( resources [ <NUM_LIT:3> ] . uri , '<STR_LIT:d>' ) <EOL> def test5_add_changed_resources ( self ) : <EOL> added = ResourceList ( ) <EOL> added . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> added . add ( Resource ( '<STR_LIT:d>' , timestamp = <NUM_LIT:4> , change = '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( added ) , <NUM_LIT:2> , "<STR_LIT>" ) <EOL> changes = ChangeList ( ) <EOL> changes . add_changed_resources ( added , change = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( changes ) , <NUM_LIT:2> , "<STR_LIT>" ) <EOL> i = iter ( changes ) <EOL> first = next ( i ) <EOL> self . assertEqual ( first . uri , '<STR_LIT:a>' , "<STR_LIT>" ) <EOL> self . assertEqual ( first . timestamp , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . assertEqual ( first . change , '<STR_LIT>' ) <EOL> second = next ( i ) <EOL> self . assertEqual ( second . timestamp , <NUM_LIT:4> , "<STR_LIT>" ) <EOL> self . assertEqual ( second . change , '<STR_LIT>' , "<STR_LIT>" ) <EOL> updated = ResourceList ( ) <EOL> updated . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:5> , change = '<STR_LIT>' ) ) <EOL> updated . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:6> , change = '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( updated ) , <NUM_LIT:2> , "<STR_LIT>" ) <EOL> changes . add_changed_resources ( updated , change = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( changes ) , <NUM_LIT:4> , "<STR_LIT>" ) <EOL> dst = ResourceList ( ) <EOL> dst . add ( changes , replace = True ) <EOL> self . assertEqual ( len ( dst ) , <NUM_LIT:3> , "<STR_LIT>" ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:a>' ] . timestamp , <NUM_LIT:5> ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:a>' ] . change , '<STR_LIT>' ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:b>' ] . timestamp , <NUM_LIT:6> ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:b>' ] . change , '<STR_LIT>' ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:d>' ] . timestamp , <NUM_LIT:4> ) <EOL> self . assertEqual ( dst . resources [ '<STR_LIT:d>' ] . change , '<STR_LIT>' ) <EOL> def test20_as_xml ( self ) : <EOL> cl = ChangeList ( ) <EOL> cl . md_from = '<STR_LIT>' <EOL> cl . add ( Resource ( '<STR_LIT:a>' , timestamp = <NUM_LIT:1> , change = '<STR_LIT>' ) ) <EOL> cl . add ( Resource ( '<STR_LIT:b>' , timestamp = <NUM_LIT:2> , change = '<STR_LIT>' ) ) <EOL> xml = cl . as_xml ( ) <EOL> self . assertTrue ( re . search ( r'<STR_LIT>' , xml ) , '<STR_LIT>' ) <EOL> self . assertTrue ( re . search ( r'<STR_LIT>' , xml ) , '<STR_LIT>' ) <EOL> self . assertTrue ( re . search ( r'<STR_LIT>' , xml ) , '<STR_LIT>' ) <EOL> def test30_parse ( self ) : <EOL> xml = '<STR_LIT>' <EOL> cl = ChangeList ( ) <EOL> cl . parse ( fh = io . StringIO ( xml ) ) <EOL> self . assertEqual ( len ( cl . resources ) , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . md [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . md [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test31_parse_no_capability ( self ) : <EOL> xml = '<STR_LIT>' <EOL> cl = ChangeList ( ) <EOL> self . assertRaises ( SitemapParseError , cl . parse , fh = io . StringIO ( xml ) ) <EOL> def test32_parse_bad_capability ( self ) : <EOL> xml = '<STR_LIT>' <EOL> cl = ChangeList ( ) <EOL> self . assertRaises ( SitemapParseError , cl . parse , fh = io . StringIO ( xml ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> suite = unittest . defaultTestLoader . loadTestsFromTestCase ( TestChangeList ) <EOL> unittest . TextTestRunner ( ) . run ( suite ) </s>
