<s> import unittest <EOL> from ics . icalendar import Calendar <EOL> from ics . component import Component <EOL> from ics . parse import Container , ContentLine <EOL> from . fixture import cal2 <EOL> import copy <EOL> fix1 = "<STR_LIT>" <EOL> fix2 = "<STR_LIT>" <EOL> class TestComponent ( unittest . TestCase ) : <EOL> def test_valueerror ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> Calendar ( cal2 ) <EOL> def test_abstract ( self ) : <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> Component . _from_container ( Container ( name = '<STR_LIT>' ) ) <EOL> def test_bad_type ( self ) : <EOL> container = Container ( name = '<STR_LIT>' ) <EOL> with self . assertRaises ( ValueError ) : <EOL> Calendar . _from_container ( container ) <EOL> def test_no_urepr ( self ) : <EOL> class Dummy ( Component ) : <EOL> pass <EOL> d = Dummy ( ) <EOL> adress = hex ( id ( d ) ) <EOL> self . assertEqual ( '<STR_LIT>' . format ( adress ) , repr ( d ) ) <EOL> def test_extractor ( self ) : <EOL> c = CT1 ( ) <EOL> c . some_attr = "<STR_LIT>" <EOL> expected = fix1 <EOL> self . assertEqual ( str ( c ) , expected ) <EOL> def test_2extractors ( self ) : <EOL> c = CT2 ( ) <EOL> c . some_attr = "<STR_LIT:foo>" <EOL> c . some_attr2 = "<STR_LIT:bar>" <EOL> expected = fix2 <EOL> self . assertEqual ( str ( c ) , expected ) <EOL> def test_empty_input ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> c = CT1 . _from_container ( cont ) <EOL> self . assertEqual ( c . _unused . name , "<STR_LIT>" ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> def test_no_match_input ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> cont2 = copy . deepcopy ( cont ) <EOL> c = CT1 . _from_container ( cont ) <EOL> self . assertEqual ( c . _unused . name , "<STR_LIT>" ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( cont2 , c . _unused ) <EOL> def test_input ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> c = CT1 . _from_container ( cont ) <EOL> self . assertEqual ( c . _unused . name , "<STR_LIT>" ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( Container ( "<STR_LIT>" ) , c . _unused ) <EOL> def test_input_plus_unused ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> unused = Container ( "<STR_LIT>" ) <EOL> unused . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> c = CT1 . _from_container ( cont ) <EOL> self . assertEqual ( c . _unused . name , "<STR_LIT>" ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( unused , c . _unused ) <EOL> def test_required_raises ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> CT2 . _from_container ( cont ) <EOL> def test_required ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> unused = Container ( "<STR_LIT>" ) <EOL> unused . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> c = CT2 . _from_container ( cont ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( unused , c . _unused ) <EOL> def test_multiple_non_allowed ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> CT1 . _from_container ( cont ) <EOL> def test_multiple ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> c = CT3 . _from_container ( cont ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( Container ( "<STR_LIT>" ) , c . _unused ) <EOL> def test_multiple_fail ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> c = CT3 . _from_container ( cont ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( Container ( "<STR_LIT>" ) , c . _unused ) <EOL> def test_multiple_unique ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> c = CT3 . _from_container ( cont ) <EOL> self . assertEqual ( c . some_attr , "<STR_LIT>" ) <EOL> self . assertEqual ( Container ( "<STR_LIT>" ) , c . _unused ) <EOL> def test_multiple_unique_required ( self ) : <EOL> cont = Container ( "<STR_LIT>" ) <EOL> cont . append ( ContentLine ( name = "<STR_LIT>" , value = "<STR_LIT>" ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> CT4 . _from_container ( cont ) <EOL> class ComponentBaseTest ( Component ) : <EOL> _TYPE = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . some_attr = "<STR_LIT>" <EOL> self . some_attr2 = "<STR_LIT>" <EOL> self . _unused = Container ( '<STR_LIT>' ) <EOL> class CT1 ( ComponentBaseTest ) : <EOL> _OUTPUTS , _EXTRACTORS = [ ] , [ ] <EOL> class CT2 ( ComponentBaseTest ) : <EOL> _OUTPUTS , _EXTRACTORS = [ ] , [ ] <EOL> class CT3 ( ComponentBaseTest ) : <EOL> _OUTPUTS , _EXTRACTORS = [ ] , [ ] <EOL> class CT4 ( ComponentBaseTest ) : <EOL> _OUTPUTS , _EXTRACTORS = [ ] , [ ] <EOL> @ CT1 . _extracts ( '<STR_LIT>' ) <EOL> def attr1 ( test , line ) : <EOL> if line : <EOL> test . some_attr = line . value <EOL> @ CT2 . _extracts ( '<STR_LIT>' , required = True ) <EOL> def attr2 ( test , line ) : <EOL> test . some_attr = line . value <EOL> @ CT3 . _extracts ( '<STR_LIT>' , multiple = True ) <EOL> def attr3 ( test , line_list ) : <EOL> if line_list : <EOL> test . some_attr = "<STR_LIT:U+002CU+0020>" . join ( map ( lambda x : x . value , line_list ) ) <EOL> @ CT4 . _extracts ( '<STR_LIT>' , required = True , multiple = True ) <EOL> def attr4 ( test , line_list ) : <EOL> test . some_attr = "<STR_LIT:U+002CU+0020>" . join ( map ( lambda x : x . value , line_list ) ) <EOL> @ CT1 . _outputs <EOL> def o_some_attr ( test , container ) : <EOL> if test . some_attr : <EOL> container . append ( ContentLine ( '<STR_LIT>' , value = test . some_attr . upper ( ) ) ) <EOL> @ CT2 . _outputs <EOL> def o_some_attr2 ( test , container ) : <EOL> if test . some_attr : <EOL> container . append ( ContentLine ( '<STR_LIT>' , value = test . some_attr . upper ( ) ) ) <EOL> @ CT2 . _outputs <EOL> def o_some_attr2bis ( test , container ) : <EOL> if test . some_attr2 : <EOL> container . append ( ContentLine ( '<STR_LIT>' , value = test . some_attr2 . upper ( ) ) ) </s>
