<s> import unittest <EOL> import dougrain <EOL> class ParseSimpleTestMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . from_object ( { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> draft = self . DRAFT ) <EOL> def testParseSimple ( self ) : <EOL> self . assertEquals ( self . doc . properties [ '<STR_LIT:name>' ] , "<STR_LIT>" ) <EOL> def testHasEmptyLinks ( self ) : <EOL> self . assertEquals ( self . doc . links , { } ) <EOL> class ParseSimpleTestDraft5 ( ParseSimpleTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> class ParseSimpleTestDraft4 ( ParseSimpleTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> class ParseSimpleTestDraft3 ( ParseSimpleTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> class ParseLinksTestMixin ( object ) : <EOL> OBJECT = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" } <EOL> ] , <EOL> } <EOL> } <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . from_object ( <EOL> self . OBJECT , <EOL> base_uri = "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> def testLoadsSingleLinkHref ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . doc . links [ "<STR_LIT>" ] . href ) <EOL> def testLoadsSingleLinkURL ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . doc . links [ "<STR_LIT>" ] . url ( ) ) <EOL> def testLoadsRelativeURLHref ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . doc . links [ "<STR_LIT>" ] . href ) <EOL> def testAbsolutesRelativeURL ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . doc . links [ "<STR_LIT>" ] . url ( ) ) <EOL> def testLoadsSelfAsLinkAndAttribute ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , self . doc . links [ "<STR_LIT>" ] . href ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . doc . links [ "<STR_LIT>" ] . url ( ) ) <EOL> self . assertEquals ( self . doc . links [ "<STR_LIT>" ] . url ( ) , self . doc . url ( ) ) <EOL> def testLoadsTitle ( self ) : <EOL> self . assertEquals ( "<STR_LIT>" , self . doc . links [ "<STR_LIT>" ] . title ) <EOL> self . assertFalse ( hasattr ( self . doc . links [ "<STR_LIT>" ] , "<STR_LIT:title>" ) ) <EOL> self . assertFalse ( hasattr ( self . doc . links [ "<STR_LIT>" ] , "<STR_LIT:title>" ) ) <EOL> def testLoadsArrayOfLinks ( self ) : <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ link . href for link in self . doc . links [ '<STR_LIT>' ] ] ) <EOL> def testLinksIsNotAnAttribute ( self ) : <EOL> self . assertFalse ( '<STR_LIT>' in self . doc . properties ) <EOL> self . assertFalse ( hasattr ( self . doc , '<STR_LIT>' ) ) <EOL> class ParseLinksTestDraft5 ( ParseLinksTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> class ParseLinksTestDraft4 ( ParseLinksTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> class ParseLinksTestDraft3 ( ParseLinksTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> class ParseEmbeddedObjectsTestMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . from_object ( <EOL> self . OBJECT , <EOL> base_uri = "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> def testLoadsSingleEmbeddedObject ( self ) : <EOL> foo = self . doc . embedded [ "<STR_LIT:foo>" ] <EOL> self . assertEquals ( "<STR_LIT>" , foo . properties [ '<STR_LIT:name>' ] ) <EOL> self . assertEquals ( <NUM_LIT> , foo . properties [ '<STR_LIT:size>' ] ) <EOL> def testLoadsArrayOfEmbeddedObjects ( self ) : <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ bar . properties [ '<STR_LIT:title>' ] <EOL> for bar in self . doc . embedded [ '<STR_LIT:bar>' ] ] ) <EOL> def testLoadsLinksInEmbeddedObject ( self ) : <EOL> link = self . doc . embedded [ "<STR_LIT>" ] . links [ "<STR_LIT>" ] <EOL> self . assertEquals ( "<STR_LIT>" , link . href ) <EOL> self . assertEquals ( "<STR_LIT>" , link . url ( ) ) <EOL> def testEmbeddedIsNotAnAttribute ( self ) : <EOL> self . assertFalse ( '<STR_LIT>' in self . doc . properties ) <EOL> self . assertFalse ( hasattr ( self . doc , '<STR_LIT>' ) ) <EOL> class ParseEmbeddedObjectsTestDraft5 ( ParseEmbeddedObjectsTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> OBJECT = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> "<STR_LIT:bar>" : [ { '<STR_LIT>' : "<STR_LIT>" } , { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:size>" : <NUM_LIT> <EOL> } , <EOL> "<STR_LIT:bar>" : [ <EOL> { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:title>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:title>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> class ParseEmbeddedObjectsTestDraft4 ( ParseEmbeddedObjectsTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> OBJECT = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:size>" : <NUM_LIT> <EOL> } , <EOL> "<STR_LIT:bar>" : [ <EOL> { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:title>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } } , <EOL> "<STR_LIT:title>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> class ParseEmbeddedObjectsTestDraft3 ( ParseEmbeddedObjectsTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> OBJECT = ParseEmbeddedObjectsTestDraft4 . OBJECT <EOL> class CurieExpansionTestMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . from_object ( self . OBJECT , <EOL> draft = self . DRAFT ) <EOL> def testExposesCurieCollection ( self ) : <EOL> expanded = self . doc . expand_curie ( '<STR_LIT>' ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> expanded ) <EOL> def testEmbeddedObjectHasParentCuries ( self ) : <EOL> sizing_doc = self . doc . embedded [ '<STR_LIT>' ] <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> sizing_doc . expand_curie ( '<STR_LIT>' ) ) <EOL> def testParentObjectDoesNotHaveEmbeddedCuried ( self ) : <EOL> self . assertEquals ( '<STR_LIT>' , self . doc . expand_curie ( '<STR_LIT>' ) ) <EOL> def testEmbeddedObjectExtendsParentCuries ( self ) : <EOL> sizing_doc = self . doc . embedded [ '<STR_LIT>' ] <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> sizing_doc . expand_curie ( '<STR_LIT>' ) ) <EOL> def testEmbeddedObjectCurieOverridesParentCurie ( self ) : <EOL> coloring_doc = self . doc . embedded [ '<STR_LIT>' ] <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> coloring_doc . expand_curie ( '<STR_LIT>' ) ) <EOL> class CurieExpansionTestDraft5 ( CurieExpansionTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> OBJECT = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : <EOL> "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] <EOL> } <EOL> } , <EOL> } <EOL> } <EOL> class CurieExpansionTestDraft4 ( CurieExpansionTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> OBJECT = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : <EOL> "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] <EOL> } <EOL> } , <EOL> } <EOL> } <EOL> class CurieExpansionTestDraft3 ( CurieExpansionTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> OBJECT = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> } <EOL> } , <EOL> } <EOL> } <EOL> class RelsTestMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document ( self . OBJECT , "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> def testHasHostLinkRel ( self ) : <EOL> host_role = self . doc . expand_curie ( '<STR_LIT>' ) <EOL> self . assertTrue ( host_role in self . doc . rels ) <EOL> self . assertEquals ( [ "<STR_LIT>" ] , <EOL> [ x . url ( ) for x in self . doc . rels [ host_role ] ] ) <EOL> def testHasConsumerEmbeddedRel ( self ) : <EOL> consumer_role = self . doc . expand_curie ( '<STR_LIT>' ) <EOL> self . assertTrue ( consumer_role in self . doc . rels ) <EOL> consumer = self . doc . rels [ consumer_role ] [ <NUM_LIT:0> ] <EOL> self . assertEquals ( "<STR_LIT>" , consumer . url ( ) ) <EOL> self . assertEquals ( "<STR_LIT>" , consumer . properties [ '<STR_LIT:name>' ] ) <EOL> def testHasApplicationLinkAndEmbeddedRels ( self ) : <EOL> application_role = self . doc . expand_curie ( '<STR_LIT>' ) <EOL> applications = self . doc . rels [ application_role ] <EOL> self . assertTrue ( self . doc . embedded [ '<STR_LIT>' ] in applications ) <EOL> self . assertTrue ( self . doc . links [ '<STR_LIT>' ] in applications ) <EOL> def testEmbeddedRelOverridesLinkRelWithSameHref ( self ) : <EOL> dept_role = self . doc . expand_curie ( '<STR_LIT>' ) <EOL> filter_url = "<STR_LIT>" <EOL> dept_2_link = [ link for link in self . doc . links [ '<STR_LIT>' ] <EOL> if link . url ( ) == filter_url ] [ <NUM_LIT:0> ] <EOL> dept_2_embedded = [ link for link in self . doc . embedded [ '<STR_LIT>' ] <EOL> if link . url ( ) == filter_url ] [ <NUM_LIT:0> ] <EOL> departments = self . doc . rels [ dept_role ] <EOL> self . assertTrue ( dept_2_embedded in departments ) <EOL> self . assertFalse ( dept_2_link in departments ) <EOL> urls = [ x . url ( ) for x in departments ] <EOL> urls . sort ( ) <EOL> self . assertEqual ( <EOL> [ "<STR_LIT>" % x for x in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] , <EOL> urls ) <EOL> class RelsTestDraft5 ( RelsTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> OBJECT = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } <EOL> ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT:name>' : "<STR_LIT>" <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> class RelsTestDraft4 ( RelsTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> OBJECT = RelsTestDraft5 . OBJECT <EOL> class RelsTestDraft3 ( RelsTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> OBJECT = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : '<STR_LIT:image>' , <EOL> '<STR_LIT>' : True <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } <EOL> ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT:name>' : "<STR_LIT>" <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> class SerializeTestsMixin ( object ) : <EOL> def checkEqualObjects ( self , obj ) : <EOL> doc = dougrain . Document . from_object ( obj , "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> self . assertEquals ( obj , doc . as_object ( ) ) <EOL> def testSimple ( self ) : <EOL> self . checkEqualObjects ( { } ) <EOL> def testAttributes ( self ) : <EOL> self . checkEqualObjects ( { "<STR_LIT>" : [ <NUM_LIT> , - <NUM_LIT> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> } ) <EOL> def testLinks ( self ) : <EOL> self . checkEqualObjects ( ParseLinksTestMixin . OBJECT ) <EOL> def testEmbeddedObjects ( self ) : <EOL> self . checkEqualObjects ( self . EMBEDDED_CASE ) <EOL> def testRels ( self ) : <EOL> self . checkEqualObjects ( self . RELS_CASE ) <EOL> def testCuries ( self ) : <EOL> self . checkEqualObjects ( self . CURIES_CASE ) <EOL> class SerializeTestsDraft5 ( SerializeTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> EMBEDDED_CASE = ParseEmbeddedObjectsTestDraft5 . OBJECT <EOL> RELS_CASE = RelsTestDraft5 . OBJECT <EOL> CURIES_CASE = CurieExpansionTestDraft5 . OBJECT <EOL> class SerializeTestsDraft4 ( SerializeTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> EMBEDDED_CASE = ParseEmbeddedObjectsTestDraft4 . OBJECT <EOL> RELS_CASE = RelsTestDraft4 . OBJECT <EOL> CURIES_CASE = CurieExpansionTestDraft4 . OBJECT <EOL> class SerializeTestsDraft3 ( SerializeTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> EMBEDDED_CASE = ParseEmbeddedObjectsTestDraft3 . OBJECT <EOL> RELS_CASE = RelsTestDraft3 . OBJECT <EOL> CURIES_CASE = CurieExpansionTestDraft3 . OBJECT <EOL> class AttributeMutationTests ( unittest . TestCase ) : <EOL> def testSetAttributeAddsAttribute ( self ) : <EOL> doc = dougrain . Document . empty ( ) <EOL> doc . set_property ( '<STR_LIT:foo>' , "<STR_LIT:bar>" ) <EOL> self . assertEquals ( "<STR_LIT:bar>" , doc . properties [ '<STR_LIT:foo>' ] ) <EOL> def testSetAttributeUpdatesAttribute ( self ) : <EOL> doc = dougrain . Document . empty ( ) <EOL> doc . set_property ( '<STR_LIT:foo>' , "<STR_LIT:bar>" ) <EOL> doc . set_property ( '<STR_LIT:foo>' , "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , doc . properties [ '<STR_LIT:foo>' ] ) <EOL> def testRemoveAttributeRemovesAttribute ( self ) : <EOL> doc = dougrain . Document . empty ( ) <EOL> doc . set_property ( '<STR_LIT:foo>' , "<STR_LIT:bar>" ) <EOL> doc . delete_property ( '<STR_LIT:foo>' ) <EOL> self . assertFalse ( hasattr ( doc , '<STR_LIT:foo>' ) ) <EOL> self . assertFalse ( '<STR_LIT:foo>' in doc . properties ) <EOL> def testBuildObjectFromEmpty ( self ) : <EOL> target = { "<STR_LIT>" : [ <NUM_LIT> , - <NUM_LIT> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> } <EOL> target_doc = dougrain . Document . from_object ( target ) <EOL> doc = dougrain . Document . empty ( ) <EOL> for key , value in target_doc . properties . items ( ) : <EOL> doc . set_property ( key , value ) <EOL> self . assertEquals ( target_doc . as_object ( ) , doc . as_object ( ) ) <EOL> class AddLinkStringTests ( unittest . TestCase ) : <EOL> def add_link ( self , doc , rel , href , ** kwargs ) : <EOL> doc . add_link ( rel , href , ** kwargs ) <EOL> def testAddSimpleLink ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> self . assertEquals ( target_doc . links , doc . links ) <EOL> def testAddWrappedLink ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } ] <EOL> } <EOL> } <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" , wrap = list ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> def testAddLinkForSecondRelKeepsFirstRel ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> self . assertEquals ( target_doc . links , doc . links ) <EOL> def testAddSecondLinkForSameRel ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] <EOL> } <EOL> } <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> self . assertEquals ( target_doc . links , doc . links ) <EOL> def testAddThirdLinkForSameRel ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] <EOL> } <EOL> } <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> self . assertEquals ( target_doc . links , doc . links ) <EOL> def testAddLinkWithExtraAttributes ( self ) : <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:title>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:title>' : "<STR_LIT>" } ] <EOL> } <EOL> } <EOL> doc = dougrain . Document . empty ( ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" , <EOL> title = "<STR_LIT>" ) <EOL> self . add_link ( doc , '<STR_LIT>' , "<STR_LIT>" , <EOL> title = "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> class AddObjectLinkTests ( AddLinkStringTests ) : <EOL> def add_link ( self , doc , rel , href , wrap = False , ** kwargs ) : <EOL> link = doc . link ( href , ** kwargs ) <EOL> doc . add_link ( rel , link , wrap = wrap ) <EOL> class AddDocumentLinkTests ( AddLinkStringTests ) : <EOL> def add_link ( self , doc , rel , href , wrap = False , ** kwargs ) : <EOL> target = dougrain . Document . empty ( href ) <EOL> self_link = target . link ( href , ** kwargs ) <EOL> target . add_link ( '<STR_LIT>' , self_link ) <EOL> doc . add_link ( rel , target , wrap = wrap ) <EOL> class AddBuilderLinkTests ( AddLinkStringTests ) : <EOL> def add_link ( self , doc , rel , href , wrap = False , ** kwargs ) : <EOL> target = dougrain . Builder ( href , ** kwargs ) <EOL> doc . add_link ( rel , target , wrap = wrap ) <EOL> class DeleteLinkTests ( unittest . TestCase ) : <EOL> def testDeleteOnlyLinkForRel ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> } <EOL> } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc . delete_link ( "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc , doc ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testDeleteEveryLinkForRel ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } <EOL> ] <EOL> } <EOL> } <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc . delete_link ( "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc . as_object ( ) , doc . as_object ( ) ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testDeleteLastLink ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target = { } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> target_doc = dougrain . Document . from_object ( target , "<STR_LIT>" ) <EOL> doc . delete_link ( "<STR_LIT>" ) <EOL> doc . delete_link ( "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc . as_object ( ) , doc . as_object ( ) ) <EOL> def testDeleteIndividualLinks ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } <EOL> ] <EOL> } <EOL> } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> doc . delete_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> doc . delete_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( { '<STR_LIT>' : "<STR_LIT>" } , <EOL> doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> doc . delete_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertFalse ( "<STR_LIT>" in doc . as_object ( ) [ '<STR_LIT>' ] ) <EOL> doc . delete_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . as_object ( ) ) <EOL> def testDeleteLinksWithoutRel ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> doc . delete_link ( href = "<STR_LIT>" ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> def testDeleteAllLinks ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target = { } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> doc . delete_link ( ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> def testDeleteLinkWithNoMatchingRel ( self ) : <EOL> initial = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> target = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } <EOL> } <EOL> doc = dougrain . Document . from_object ( initial , "<STR_LIT>" ) <EOL> doc . delete_link ( rel = "<STR_LIT>" . join ( doc . links . keys ( ) ) ) <EOL> self . assertEquals ( target , doc . as_object ( ) ) <EOL> def testDeleteLinkWithNoLinks ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> target = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> doc . delete_link ( ) <EOL> self . assertEquals ( target , doc ) <EOL> class EmbedTestMixin ( object ) : <EOL> OBJECT_WITH_SELF = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> } <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> self . embedded1 = dougrain . Document . from_object ( { "<STR_LIT:foo>" : "<STR_LIT:bar>" } , <EOL> draft = self . DRAFT ) <EOL> self . embedded2 = dougrain . Document . from_object ( { "<STR_LIT>" : "<STR_LIT>" } , <EOL> draft = self . DRAFT ) <EOL> self . embedded3 = dougrain . Document . from_object ( { "<STR_LIT>" : "<STR_LIT>" } , <EOL> draft = self . DRAFT ) <EOL> self . embedded_with_self = dougrain . Document . from_object ( <EOL> self . OBJECT_WITH_SELF , <EOL> draft = self . DRAFT ) <EOL> def testEmbed ( self ) : <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . embedded1 . as_object ( ) <EOL> } <EOL> } <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded1 ) <EOL> self . assertEquals ( expected , self . doc . as_object ( ) ) <EOL> self . assertEquals ( self . embedded1 , self . doc . embedded [ '<STR_LIT>' ] ) <EOL> def testEmbedWrapped ( self ) : <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ self . embedded1 . as_object ( ) ] <EOL> } <EOL> } <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded1 , wrap = True ) <EOL> self . assertEquals ( expected , self . doc . as_object ( ) ) <EOL> self . assertEquals ( [ self . embedded1 ] , self . doc . embedded [ '<STR_LIT>' ] ) <EOL> def testEmbedAnotherRel ( self ) : <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . embedded2 . as_object ( ) , <EOL> '<STR_LIT>' : self . embedded3 . as_object ( ) , <EOL> } <EOL> } <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded2 ) <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded3 ) <EOL> self . assertEquals ( expected , self . doc . as_object ( ) ) <EOL> self . assertEquals ( self . embedded2 , self . doc . embedded [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( self . embedded3 , self . doc . embedded [ '<STR_LIT>' ] ) <EOL> def testEmbedSameRel ( self ) : <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> self . embedded1 . as_object ( ) , <EOL> self . embedded2 . as_object ( ) , <EOL> self . embedded3 . as_object ( ) <EOL> ] <EOL> } <EOL> } <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded1 ) <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded2 ) <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded3 ) <EOL> self . assertEquals ( expected , self . doc . as_object ( ) ) <EOL> self . assertEquals ( [ self . embedded1 , self . embedded2 , self . embedded3 ] , <EOL> self . doc . embedded [ '<STR_LIT>' ] ) <EOL> def testEmbedDocumentWithSelfLink ( self ) : <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded_with_self ) <EOL> self . assertEquals ( self . EXPECTED_WITH_SELF_LINK , <EOL> self . doc . as_object ( ) ) <EOL> class EmbedTestDraft5 ( EmbedTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> EXPECTED_WITH_SELF_LINK = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : EmbedTestMixin . OBJECT_WITH_SELF <EOL> } <EOL> } <EOL> EXPECTED_WITH_SELF_LINK_WRAPPED = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ EmbedTestMixin . OBJECT_WITH_SELF ] <EOL> } <EOL> } <EOL> def testEmbedWrappedWithSelfLink ( self ) : <EOL> self . doc . embed ( '<STR_LIT>' , self . embedded_with_self , wrap = True ) <EOL> self . assertEquals ( self . EXPECTED_WITH_SELF_LINK_WRAPPED , <EOL> self . doc . as_object ( ) ) <EOL> class EmbedTestDraft4 ( EmbedTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> EXPECTED_WITH_SELF_LINK = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : EmbedTestMixin . OBJECT_WITH_SELF <EOL> } <EOL> } <EOL> class EmbedTestDraft3 ( EmbedTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> EXPECTED_WITH_SELF_LINK = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : EmbedTestMixin . OBJECT_WITH_SELF <EOL> } <EOL> } <EOL> class TestIteration ( unittest . TestCase ) : <EOL> def testASingleDocumentCanBeIterated ( self ) : <EOL> for draft in ( dougrain . drafts . DRAFT_3 , <EOL> dougrain . drafts . DRAFT_4 , <EOL> dougrain . drafts . DRAFT_5 ) : <EOL> the_doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = draft ) <EOL> the_doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> count = <NUM_LIT:0> <EOL> for a_doc in the_doc : <EOL> count += <NUM_LIT:1> <EOL> self . assertEquals ( the_doc , a_doc ) <EOL> self . assertEquals ( <NUM_LIT:1> , count ) <EOL> class DeleteEmbeddedTestsMixin ( object ) : <EOL> EMBEDDED_KEY = dougrain . document . EMBEDDED_KEY <EOL> def make_doc ( self , href , * args , ** kwargs ) : <EOL> result = dougrain . Document . empty ( "<STR_LIT>" , * args , <EOL> draft = self . DRAFT , ** kwargs ) <EOL> result . add_link ( '<STR_LIT>' , href ) <EOL> return result <EOL> def testDeleteOnlyEmbedForRel ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> target_doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . delete_embedded ( "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . embedded ) <EOL> self . assertTrue ( '<STR_LIT:root>' in doc . embedded ) <EOL> def testDeleteEveryEmbedForRel ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> target_doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . delete_embedded ( "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . embedded ) <EOL> self . assertTrue ( '<STR_LIT:root>' in doc . embedded ) <EOL> def testDeleteLastEmbed ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . delete_embedded ( '<STR_LIT:root>' ) <EOL> doc . delete_embedded ( '<STR_LIT>' ) <EOL> self . assertEquals ( target_doc . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> def testDeleteIndividualEmbeds ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc2 = self . make_doc ( "<STR_LIT>" ) <EOL> doc2 . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc2 . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc2 . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc3 = self . make_doc ( "<STR_LIT>" ) <EOL> doc3 . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc3 . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc4 = self . make_doc ( "<STR_LIT>" ) <EOL> doc4 . embed ( '<STR_LIT:root>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc5 = self . make_doc ( "<STR_LIT>" ) <EOL> doc . delete_embedded ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( doc2 . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> doc . delete_embedded ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( doc3 . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> doc . delete_embedded ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( doc4 . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> doc . delete_embedded ( "<STR_LIT:root>" , "<STR_LIT>" ) <EOL> self . assertEquals ( doc5 . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> def testDeleteEmbedsWithoutRel ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> target_doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . delete_embedded ( href = "<STR_LIT>" ) <EOL> self . assertEquals ( target_doc . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> def testDeleteAllEmbeds ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . delete_embedded ( ) <EOL> self . assertEquals ( target_doc . as_object ( ) . get ( self . EMBEDDED_KEY ) , <EOL> doc . as_object ( ) . get ( self . EMBEDDED_KEY ) ) <EOL> def testDeleteEmbedWithMissingRel ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> target_doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> target_doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> missing_rel = '<STR_LIT>' . join ( doc . embedded . keys ( ) ) + '<STR_LIT:_>' <EOL> doc . delete_embedded ( missing_rel ) <EOL> self . assertEquals ( target_doc . as_object ( ) , doc . as_object ( ) ) <EOL> def testDeleteEmbedWithNoEmbeds ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> target_doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . delete_embedded ( ) <EOL> self . assertEquals ( target_doc . as_object ( ) , doc . as_object ( ) ) <EOL> def testAutomaticLink ( self ) : <EOL> doc = self . make_doc ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , self . make_doc ( "<STR_LIT>" ) ) <EOL> doc . delete_embedded ( '<STR_LIT>' ) <EOL> self . assertAutomaticLink ( '<STR_LIT>' in doc . links ) <EOL> class DeleteEmbeddedTestsDraft5 ( DeleteEmbeddedTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> assertAutomaticLink = unittest . TestCase . assertTrue <EOL> class DeleteEmbeddedTestsDraft4 ( DeleteEmbeddedTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> assertAutomaticLink = unittest . TestCase . assertFalse <EOL> class DeleteEmbeddedTestsDraft3 ( DeleteEmbeddedTestsMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> assertAutomaticLink = unittest . TestCase . assertFalse <EOL> class CurieMutationTestMixin ( object ) : <EOL> def make_doc ( self , href , * args , ** kwargs ) : <EOL> result = dougrain . Document . empty ( "<STR_LIT>" , * args , <EOL> draft = self . DRAFT , ** kwargs ) <EOL> result . add_link ( '<STR_LIT>' , href ) <EOL> return result <EOL> def setUp ( self ) : <EOL> self . doc = self . make_doc ( "<STR_LIT>" ) <EOL> self . doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> def testCurieJSONHasCorrectType ( self ) : <EOL> self . assertEquals ( type ( self . doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , list ) <EOL> def testSetCurie ( self ) : <EOL> new_doc = dougrain . Document ( self . doc . as_object ( ) , self . doc . base_uri , <EOL> draft = self . DRAFT ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> new_doc . expand_curie ( "<STR_LIT>" ) ) <EOL> def testReplaceCurie ( self ) : <EOL> self . doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> new_doc = dougrain . Document ( self . doc . as_object ( ) , self . doc . base_uri ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> new_doc . expand_curie ( "<STR_LIT>" ) ) <EOL> def testDropCurie ( self ) : <EOL> self . doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . doc . drop_curie ( '<STR_LIT>' ) <EOL> new_doc = dougrain . Document ( self . doc . as_object ( ) , self . doc . base_uri , <EOL> draft = self . DRAFT ) <EOL> self . assertEquals ( "<STR_LIT>" , self . doc . expand_curie ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> new_doc . expand_curie ( "<STR_LIT>" ) ) <EOL> def testDropSingleCurie ( self ) : <EOL> self . doc . drop_curie ( '<STR_LIT>' ) <EOL> self . assertEquals ( "<STR_LIT>" , self . doc . expand_curie ( "<STR_LIT>" ) ) <EOL> class CurieMutationTestDraft5 ( CurieMutationTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> def testCurieJSONHasCorrectType ( self ) : <EOL> self . assertEquals ( type ( self . doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , list ) <EOL> class CurieMutationTestDraft4 ( CurieMutationTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> def testCurieJSONHasCorrectType ( self ) : <EOL> self . assertEquals ( type ( self . doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , list ) <EOL> class CurieMutationTestDraft3 ( CurieMutationTestMixin , unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> def testCurieJSONHasCorrectType ( self ) : <EOL> self . assertEquals ( type ( self . doc . as_object ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , dict ) <EOL> class CurieHidingTests ( unittest . TestCase ) : <EOL> def testCuriesAreNotLinksDraft5 ( self ) : <EOL> doc = dougrain . Document ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> } , "<STR_LIT>" , draft = dougrain . drafts . DRAFT_5 ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testCuriesAreNotLinksDraft4 ( self ) : <EOL> doc = dougrain . Document ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> } , "<STR_LIT>" , draft = dougrain . drafts . DRAFT_4 ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testCuriesAreNotLinksDraft3 ( self ) : <EOL> doc = dougrain . Document ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> } , "<STR_LIT>" , draft = dougrain . drafts . DRAFT_3 ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testDraft4CuriesAreLinksInDraft43Documents ( self ) : <EOL> modern_doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_4 ) <EOL> modern_doc . set_curie ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> doc = dougrain . Document . from_object ( modern_doc . as_object ( ) , <EOL> base_uri = "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_3 ) <EOL> self . assertTrue ( '<STR_LIT>' in doc . links ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testDraft5CuriesAreLinksInDraft43Documents ( self ) : <EOL> modern_doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_5 ) <EOL> modern_doc . set_curie ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> doc = dougrain . Document . from_object ( modern_doc . as_object ( ) , <EOL> base_uri = "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_3 ) <EOL> self . assertTrue ( '<STR_LIT>' in doc . links ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> def testDraft3CuriesAreLinksInDraft5Document ( self ) : <EOL> doc = dougrain . Document ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> } , "<STR_LIT>" , draft = dougrain . drafts . DRAFT_5 ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> self . assertTrue ( '<STR_LIT>' in doc . links ) <EOL> def testDraft3CuriesAreLinksInDraft4Document ( self ) : <EOL> doc = dougrain . Document ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:name>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> } , "<STR_LIT>" , draft = dougrain . drafts . DRAFT_4 ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . links ) <EOL> self . assertTrue ( '<STR_LIT>' in doc . links ) <EOL> class LinkCanonicalizationTestsMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> self . doc . set_curie ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def testFindsLinksByFullRelTypeURI ( self ) : <EOL> self . doc . add_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( self . doc . links [ "<STR_LIT>" ] , <EOL> self . doc . links [ "<STR_LIT>" ] ) <EOL> def testFindsLinksByRelTypePath ( self ) : <EOL> self . doc . add_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( self . doc . links [ "<STR_LIT>" ] , <EOL> self . doc . links [ "<STR_LIT>" ] ) <EOL> def testMergesLinksAddedWithSynonymous ( self ) : <EOL> self . doc . add_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . doc . add_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . doc . add_link ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ link . href for link in self . doc . links [ "<STR_LIT>" ] ] ) <EOL> def testMergesLinkswhenLoading ( self ) : <EOL> links = dict ( self . CURIES ) <EOL> links . update ( { <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> } ) <EOL> self . doc = dougrain . Document . from_object ( <EOL> { "<STR_LIT>" : links } , <EOL> base_uri = "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> self . doc . set_curie ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEquals ( <EOL> set ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> set ( link . href for link in self . doc . links [ "<STR_LIT>" ] ) ) <EOL> class LinkCanonicalizationTestsDraft5 ( LinkCanonicalizationTestsMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> CURIES = { <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : True } <EOL> ] <EOL> } <EOL> class LinkCanonicalizationTestsDraft4 ( LinkCanonicalizationTestsMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> CURIES = { <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : True } <EOL> ] <EOL> } <EOL> class LinkCanonicalizationTestsDraft3 ( LinkCanonicalizationTestsMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> CURIES = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> } <EOL> class EmbeddedCanonicalizationTestMixin ( object ) : <EOL> def setUp ( self ) : <EOL> self . doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = self . DRAFT ) <EOL> self . doc . set_curie ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def new_doc ( self , uri ) : <EOL> doc = dougrain . Document . empty ( uri , draft = self . DRAFT ) <EOL> doc . add_link ( '<STR_LIT>' , uri ) <EOL> doc . set_property ( "<STR_LIT:name>" , uri ) <EOL> return doc <EOL> def testFindsEmbeddedResourcesByFullRelTypeURI ( self ) : <EOL> self . doc . embed ( "<STR_LIT>" , self . new_doc ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( self . doc . embedded [ "<STR_LIT>" ] , <EOL> self . doc . embedded [ "<STR_LIT>" ] ) <EOL> def testFindsEmbeddedResourcesByRelTypePath ( self ) : <EOL> self . doc . embed ( "<STR_LIT>" , self . new_doc ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( self . doc . embedded [ "<STR_LIT>" ] , <EOL> self . doc . embedded [ "<STR_LIT>" ] ) <EOL> def testMergesEmbeddedResourcesAddedWithSynonymous ( self ) : <EOL> self . doc . embed ( "<STR_LIT>" , self . new_doc ( "<STR_LIT>" ) ) <EOL> self . doc . embed ( "<STR_LIT>" , self . new_doc ( "<STR_LIT>" ) ) <EOL> self . doc . embed ( "<STR_LIT>" , self . new_doc ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ embedded . properties [ '<STR_LIT:name>' ] <EOL> for embedded in self . doc . embedded [ "<STR_LIT>" ] ] ) <EOL> class EmbeddedCanonicalizationTestDraft5 ( EmbeddedCanonicalizationTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_5 <EOL> class EmbeddedCanonicalizationTestDraft4 ( EmbeddedCanonicalizationTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_4 <EOL> class EmbeddedCanonicalizationTestDraft3 ( EmbeddedCanonicalizationTestMixin , <EOL> unittest . TestCase ) : <EOL> DRAFT = dougrain . drafts . DRAFT_3 <EOL> class EdgeCasesTests ( unittest . TestCase ) : <EOL> def testUrlOfDocumentWithMultipleSelfLinksFromFirstSelfLink ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , doc . url ( ) ) <EOL> def testSetReservedAttributeSilentlyFails ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> doc . set_property ( '<STR_LIT>' , { '<STR_LIT>' : { '<STR_LIT>' : "<STR_LIT>" } } ) <EOL> doc . set_property ( '<STR_LIT>' , { '<STR_LIT>' : { '<STR_LIT:foo>' : "<STR_LIT:bar>" } } ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . properties ) <EOL> self . assertIsNone ( doc . url ( ) ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . properties ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . embedded ) <EOL> def testDeleteReservedAttributeSilentlyFails ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , dougrain . Document . from_object ( { '<STR_LIT:foo>' : "<STR_LIT:bar>" } , <EOL> "<STR_LIT>" ) ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> with self . assertRaises ( KeyError ) : <EOL> doc . delete_property ( '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> doc . delete_property ( '<STR_LIT>' ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . properties ) <EOL> self . assertEquals ( "<STR_LIT>" , doc . url ( ) ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . properties ) <EOL> self . assertEquals ( "<STR_LIT:bar>" , doc . embedded [ '<STR_LIT>' ] . properties [ '<STR_LIT:foo>' ] ) <EOL> def testEmbedDocumentInItself ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . set_property ( '<STR_LIT:name>' , "<STR_LIT>" ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . embed ( '<STR_LIT>' , doc ) <EOL> self . assertFalse ( '<STR_LIT>' in doc . embedded ) <EOL> class ExplicitDraftTests ( unittest . TestCase ) : <EOL> def testDraft3DocumentHasOldCurieBehaviour ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_3 ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_3 ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> links = doc . as_object ( ) [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' in links ) <EOL> self . assertFalse ( '<STR_LIT>' in links ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , dict ) ) <EOL> doc . set_curie ( '<STR_LIT:foo>' , "<STR_LIT>" ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , list ) ) <EOL> def testDraft4DocumentHasNewCurieBehaviour ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_4 ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_4 ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> links = doc . as_object ( ) [ '<STR_LIT>' ] <EOL> self . assertFalse ( '<STR_LIT>' in links ) <EOL> self . assertTrue ( '<STR_LIT>' in links ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , list ) ) <EOL> doc . set_curie ( '<STR_LIT:foo>' , "<STR_LIT>" ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , list ) ) <EOL> def testDraft5DocumentHasNewCurieBehaviour ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_5 ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_5 ) <EOL> doc . add_link ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> doc . set_curie ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> links = doc . as_object ( ) [ '<STR_LIT>' ] <EOL> self . assertFalse ( '<STR_LIT>' in links ) <EOL> self . assertTrue ( '<STR_LIT>' in links ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , list ) ) <EOL> doc . set_curie ( '<STR_LIT:foo>' , "<STR_LIT>" ) <EOL> curie = links [ '<STR_LIT>' ] <EOL> self . assertTrue ( isinstance ( curie , list ) ) <EOL> class DraftDetectionTests ( unittest . TestCase ) : <EOL> def testDocumentsWithCurieAreDraft3 ( self ) : <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : { } } } , <EOL> "<STR_LIT>" ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_3 ) <EOL> def testDocumentsWithCuriesAreDraft5 ( self ) : <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : [ ] } } , <EOL> "<STR_LIT>" ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_5 ) <EOL> def testDocumentsWithNoCurieKeyAreLatest ( self ) : <EOL> doc = dougrain . Document . empty ( "<STR_LIT>" ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . LATEST ) <EOL> def testLatestDraftIsDraft5 ( self ) : <EOL> doc = dougrain . Document . from_object ( { } , "<STR_LIT>" , <EOL> draft = dougrain . drafts . LATEST ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_5 ) <EOL> def testExplicitDraftOverridesAutodetection ( self ) : <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True } } } , <EOL> "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_5 <EOL> ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_5 ) <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True } } } , <EOL> "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_4 <EOL> ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_4 ) <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True } ] } } , <EOL> "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_4 <EOL> ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_4 ) <EOL> doc = dougrain . Document . from_object ( <EOL> { '<STR_LIT>' : { '<STR_LIT>' : [ ] } } , <EOL> "<STR_LIT>" , <EOL> draft = dougrain . drafts . DRAFT_3 <EOL> ) <EOL> self . assertEquals ( doc . draft , dougrain . drafts . DRAFT_3 ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
