"""

Demonstrate/test static_map_rdf

"""
import rdflib
import static_map_rdf
import debugtools

################################################################
#
#  SAMPLE APPLICATION
#

NS = rdflib.Namespace("http://example.com/ns")

#
# Here's a sample class
#
class Person:
    def __eq__(self, other):
        return self.__dict__ == other.__dict__
    def __repr__(self):
        return "Person("+debugtools.dict_repr(self.__dict__)+")"

#
# Tell the mapper about this class
#

static_map_rdf.autoconvert(Person, name=NS, age=NS)

################################################################

def loopback(prmap, obj):
    node = prmap.toRDF(obj)
    obj2 = prmap.fromRDF(node)
    if obj == obj2:
        pass
    else:
        debugtools.debug("toRDF", "%s != %s" % (`obj`, `obj2`))
        assert(False)
    debugtools.debug("toRDF", "got back %s" % obj2)


    

def run():
    graph = rdflib.ConjunctiveGraph()
    prmap = static_map_rdf.PythonRDFMap(graph)

    loopback(prmap, 5)

    loopback(prmap, "Hello")

    eric = Person()
    eric.name=u"Eric Lastname"
    eric.age=31
    loopback(prmap, eric)
    return True


if __name__ == "__main__":
    import doctest, sys
    doctest.testmod(sys.modules[__name__])

    debugtools.tags.add("toRDF")
    run()
