<s> import unittest <EOL> from rdflib import ConjunctiveGraph , URIRef , Namespace <EOL> from rdflib . py3compat import b <EOL> TEST_BASE = '<STR_LIT>' <EOL> class NQuadsParserTest ( unittest . TestCase ) : <EOL> def _load_example ( self ) : <EOL> g = ConjunctiveGraph ( ) <EOL> with open ( "<STR_LIT>" , "<STR_LIT:rb>" ) as data : <EOL> g . parse ( data , format = "<STR_LIT>" ) <EOL> return g <EOL> def test_01_simple_open ( self ) : <EOL> g = self . _load_example ( ) <EOL> assert len ( g . store ) == <NUM_LIT> <EOL> def test_02_contexts ( self ) : <EOL> g = self . _load_example ( ) <EOL> assert len ( [ x for x in g . store . contexts ( ) ] ) == <NUM_LIT:16> <EOL> def test_03_get_value ( self ) : <EOL> g = self . _load_example ( ) <EOL> s = URIRef ( "<STR_LIT>" ) <EOL> FOAF = Namespace ( "<STR_LIT>" ) <EOL> self . assertTrue ( g . value ( s , FOAF . name ) . eq ( "<STR_LIT>" ) ) <EOL> def test_context_is_optional ( self ) : <EOL> g = ConjunctiveGraph ( ) <EOL> with open ( "<STR_LIT>" , "<STR_LIT:rb>" ) as data : <EOL> g . parse ( data , format = "<STR_LIT>" ) <EOL> assert len ( g ) > <NUM_LIT:0> <EOL> def test_serialize ( self ) : <EOL> g = ConjunctiveGraph ( ) <EOL> uri1 = URIRef ( "<STR_LIT>" ) <EOL> uri2 = URIRef ( "<STR_LIT>" ) <EOL> bob = URIRef ( u'<STR_LIT>' ) <EOL> likes = URIRef ( u'<STR_LIT>' ) <EOL> pizza = URIRef ( u'<STR_LIT>' ) <EOL> g . get_context ( uri1 ) . add ( ( bob , likes , pizza ) ) <EOL> g . get_context ( uri2 ) . add ( ( bob , likes , pizza ) ) <EOL> s = g . serialize ( format = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( [ x for x in s . split ( b ( "<STR_LIT:\n>" ) ) if x . strip ( ) ] ) , <NUM_LIT:2> ) <EOL> g2 = ConjunctiveGraph ( ) <EOL> g2 . parse ( data = s , format = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( g ) , len ( g2 ) ) <EOL> self . assertEqual ( sorted ( x . identifier for x in g . contexts ( ) ) , <EOL> sorted ( x . identifier for x in g2 . contexts ( ) ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
