# Path: rdfalchemy/orm.py
# def mapper(*classes):
#     """
#     Maps the classes given to allow descriptors with ranges to the
#     proper Class of that type
# 
#     The default, if no args are provided, is to map recursively all subclasses
#     of :class:`~rdfalchemy.rdfSubject.rdfSubject`
# 
#     Returns a dict of {rdf_type: mapped_class} for further processing
#     """
#     if not classes:
#         classes = allsub(rdfSubject)
#     class_dict = dict([(str(cl.rdf_type), cl) for cl in classes])
#     for cl in classes:  # for each class
#         for v in cl.__dict__.values():  # for each desciptor
#             # if its a descriptor with a range
#             if isinstance(v, rdfAbstract) and v.range_type:
#                 try:
#                     v._mappedClass = class_dict[str(v.range_type)]
#                 except KeyError:
#                     log.warn("No Class Found\nFailed to map %s range of %s" % (
#                         v, v.range_type))
#     return class_dict
# 
# Path: rdfalchemy/samples/doap.py
# FOAF = Namespace("http://xmlns.com/foaf/0.1/")
# 
# Path: rdfalchemy/samples/foaf.py
# class Person(Agent):
#     rdf_type = FOAF.Person
#     first = rdfSingle(FOAF.firstName)
#     last = rdfSingle(FOAF.surname)
#     givenname = rdfSingle(FOAF.givenname)
#     surname = rdfSingle(FOAF.surname)


import rdfalchemy
import logging
from rdfalchemy.orm import mapper
from rdfalchemy.samples.doap import FOAF
from rdfalchemy.samples.foaf import Person
from rdflib import ConjunctiveGraph

def test_addBNodeKnowsL():
    Person.knows = rdfalchemy.rdfList(
        FOAF.knowsL, range_type=FOAF.Person)
    p1 = Person(first="PhilipL")
    p2 = Person(last="Cooper", first="Ben")
    p3 = Person(last="Cooper", first="Matt")
    p1.knows = [p2, p3]
    p1 = Person.get_by(first="PhilipL")
    log.info("db len is %s" % len(Person.db))
    assert len(p1.knows) == 2
    del p1


def test_addBNodeKnowsC():
    Person.knows = rdfalchemy.rdfContainer(
        FOAF.knowsC, range_type=FOAF.Person)
    mapper()
    p1 = Person(first="PhilipC")
    p2 = Person(last="Cooper", first="Ben")
    p3 = Person(last="Cooper", first="Matt")
    p1.knows = [p2, p3]
    p1 = Person.get_by(first="PhilipC")
    log.info("db len is %s" % len(Person.db))
    assert len(p1.knows) == 2
    del p1


def test_addBNodeKnowsM():
    Person.knows = rdfalchemy.rdfMultiple(

# Path: rdfalchemy/orm.py
# def mapper(*classes):
#     """
#     Maps the classes given to allow descriptors with ranges to the
#     proper Class of that type
# 
#     The default, if no args are provided, is to map recursively all subclasses
#     of :class:`~rdfalchemy.rdfSubject.rdfSubject`
# 
#     Returns a dict of {rdf_type: mapped_class} for further processing
#     """
#     if not classes:
#         classes = allsub(rdfSubject)
#     class_dict = dict([(str(cl.rdf_type), cl) for cl in classes])
#     for cl in classes:  # for each class
#         for v in cl.__dict__.values():  # for each desciptor
#             # if its a descriptor with a range
#             if isinstance(v, rdfAbstract) and v.range_type:
#                 try:
#                     v._mappedClass = class_dict[str(v.range_type)]
#                 except KeyError:
#                     log.warn("No Class Found\nFailed to map %s range of %s" % (
#                         v, v.range_type))
#     return class_dict
# 
# Path: rdfalchemy/samples/doap.py
# FOAF = Namespace("http://xmlns.com/foaf/0.1/")
# 
# Path: rdfalchemy/samples/foaf.py
# class Person(Agent):
#     rdf_type = FOAF.Person
#     first = rdfSingle(FOAF.firstName)
#     last = rdfSingle(FOAF.surname)
#     givenname = rdfSingle(FOAF.givenname)
#     surname = rdfSingle(FOAF.surname)


# Path: test/get_test.py
import rdfalchemy
import logging
from rdfalchemy.orm import mapper
from rdfalchemy.samples.doap import FOAF
from rdfalchemy.samples.foaf import Person
from rdflib import ConjunctiveGraph


def test_addBNodeKnowsL():
    Person.knows = rdfalchemy.rdfList(
        FOAF.knowsL, range_type=FOAF.Person)
    p1 = Person(first="PhilipL")
    p2 = Person(last="Cooper", first="Ben")
    p3 = Person(last="Cooper", first="Matt")
    p1.knows = [p2, p3]
    p1 = Person.get_by(first="PhilipL")
    log.info("db len is %s" % len(Person.db))
    assert len(p1.knows) == 2
    del p1


def test_addBNodeKnowsC():
    Person.knows = rdfalchemy.rdfContainer(
        FOAF.knowsC, range_type=FOAF.Person)
    mapper()
    p1 = Person(first="PhilipC")
    p2 = Person(last="Cooper", first="Ben")
    p3 = Person(last="Cooper", first="Matt")
    p1.knows = [p2, p3]
    p1 = Person.get_by(first="PhilipC")
    log.info("db len is %s" % len(Person.db))
    assert len(p1.knows) == 2
    del p1


def test_addBNodeKnowsM():
    Person.knows = rdfalchemy.rdfMultiple(

        FOAF.knowsM, range_type=FOAF.Person)