コード例 #1
0
def test_NamespaceConfigParser_instantiation_with_node_factory_override_3():
    ns = Namespace(default_node_factory=NamespaceNodeBaseSubclass)
    nfactory = partial(ns.add_exactly_one,
                       node_factory=NamespaceNodeBaseSubclass)
    nscp = NamespaceConfigParser(node_factory=nfactory)
    new_node = nscp.new_node('.test')
    assert (isinstance(new_node, NamespaceNodeBaseSubclass))
コード例 #2
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_root_delegate(self):
        ns = Namespace()
        ns.add('.a.few.nodes')

        #make sure it exists with this name
        ns.a.few.nodes.attr = "val"
        assert ns.a.few.nodes.attr == "val"
コード例 #3
0
def test_parse_existing_namespace():
    test_dict = {
        "all": {
            "work": {
                "no": {
                    "play": {
                        "dull_boy": {}
                    }
                }
            }
        },
        "hackers": {
            "on": {
                "planet": {
                    "earth": {}
                }
            }
        }
    }

    ns = Namespace()
    nscp = NamespaceConfigParser2(namespace=ns)
    nscp.parse(dictConfig=test_dict)

    for nsid in get_nsid_ancestry('.all.work.no.play.dull_boy'):
        assert isinstance(ns.get(nsid), NamespaceNodeBase)

    for nsid in get_nsid_ancestry('.hackers.on.planet.earth'):
        assert isinstance(ns.get(nsid), NamespaceNodeBase)
コード例 #4
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_get_handle(self):
        ns = Namespace()
        ns.add(".add.some.stuff.here")
        ns.add(".other.stuff.added.here.now")

        handle = ns.get_handle(".other.stuff")
        assert isinstance(handle.added.here, NamespaceNodeBase)
コード例 #5
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_handle_remove(self):
        ns = Namespace()
        ns.add(".more.stuff.here.too")

        handle = ns.get_handle(".more.stuff.here")
        node = handle.remove(".too")

        assert node.nsid.nsid == ".more.stuff.here.too"
コード例 #6
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_add_node_return2(self):
     ns = Namespace()
     new_nsid = '.a.b'
     new_nodes = ns.add(new_nsid)
     #- add returns all the new nodes created in order of creation
     #- so the last one in the list will be the deepest child
     new_node = new_nodes[-1]
     self.assertEqual(str(new_nodes[-1].nsid), new_nsid)
コード例 #7
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_delete_node(self):
     ns = Namespace()
     new_nsid = '.a.b.c.d'
     ns.add(new_nsid)
     node = ns.remove(new_nsid)
     self.assertEqual(str(node.nsid), new_nsid)
     with self.assertRaises(NamespaceLookupError):
         ns.get(new_nsid)
コード例 #8
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_add_exactly_one_bad_input(self):
        ns = Namespace()
        nsid = '.two.nodes'
        with self.assertRaises(ValueError):
            new_node = ns.add_exactly_one(nsid)

        nsid = '.now.three.nodes'
        with self.assertRaises(ValueError):
            new_node = ns.add_exactly_one(nsid)
コード例 #9
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_default_node_factory(self):
        class NewNamespaceNodeBase(NamespaceNodeBase):
            def __init__(self, nsid=None, namespace=None):
                super().__init__(nsid=nsid, namespace=namespace)

        ns = Namespace(default_node_factory=NewNamespaceNodeBase)
        new_nodes = ns.add('.this.is.all.new')

        for node in new_nodes:
            self.assertIsInstance(node, NewNamespaceNodeBase)
コード例 #10
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
def test_get_subnodes_from_handle():
    ns = Namespace()
    ns.add(".a.few.nodes.here.and.there.and.everywhere")
    handle = ns.get_handle(".a.few")

    subnodes = handle.get_subnodes('.nodes.here.and.there')
    nsids = [str(x.nsid) for x in subnodes]

    assert nsids == [
        '.a.few.nodes.here.and.there.and',
        '.a.few.nodes.here.and.there.and.everywhere'
    ]
コード例 #11
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
def test_get_subnodes():
    ns = Namespace()
    ns.add(".a.few.nodes.here.and.there.and.everywhere")

    subnodes = ns.get_subnodes('.a.few')
    nsids = [str(x.nsid) for x in subnodes]

    assert nsids == [
        '.a.few.nodes', '.a.few.nodes.here', '.a.few.nodes.here.and',
        '.a.few.nodes.here.and.there', '.a.few.nodes.here.and.there.and',
        '.a.few.nodes.here.and.there.and.everywhere'
    ]
コード例 #12
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
def test_get_subnodes_from_nested_handles(caplog):
    ns = Namespace()
    #caplog.set_level(logging.DEBUG)
    ns.add(".a.few.nodes.here.and.there.and.everywhere")
    handle1 = ns.get_handle(".a.few")
    handle2 = handle1.get_handle(".nodes")

    subnodes = handle2.get_subnodes('.here.and.there')
    nsids = [str(x.nsid) for x in subnodes]

    assert nsids == [
        '.a.few.nodes.here.and.there.and',
        '.a.few.nodes.here.and.there.and.everywhere'
    ]
コード例 #13
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_walk(self):
     ns = Namespace()
     ns.add('.all.work.no_play.dull_boy')
     ns.add('.hackers.on.planet.earth')
     test_dict = {
         ".": {
             "all": {
                 "work": {
                     "no_play": {
                         "dull_boy": {}
                     }
                 }
             },
             "hackers": {
                 "on": {
                     "planet": {
                         "earth": {}
                     }
                 }
             }
         }
     }
     self.assertEqual(ns.walk(), test_dict)
コード例 #14
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_add_then_get_new_node(self):
     ns = Namespace()
     new_nsid = '.a.b.c.d.e'
     ns.add(new_nsid)
     node = ns.get(new_nsid)
     self.assertEqual(new_nsid, str(node.nsid))
コード例 #15
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_add_bad_node2(self):
     ns = Namespace()
     # nsids must start with a dot
     new_nsid = 'a.b'
     with self.assertRaises(InvalidNsidError):
         new_nodes = ns.add(new_nsid)
コード例 #16
0
def blank_namespace():
    return Namespace()
コード例 #17
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_basic_walk(self):
     ns = Namespace()
     self.assertEqual({".": {}}, ns.walk())
コード例 #18
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
    def test_bad_get2(self):
        ns = Namespace()
        ns.add('.something.that')

        with self.assertRaises(NamespaceLookupError):
            ns.get(".something.that.does.not.exist.and.is.long")
コード例 #19
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_get_root_node(self):
     ns = Namespace()
     root = ns.get('.')
     self.assertEqual(ns.root, root)
コード例 #20
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_add_exactly_one_happy_path(self):
     ns = Namespace()
     nsid = '.one_new_node'
     new_node = ns.add_exactly_one(nsid)
     self.assertEqual(str(new_node.nsid), nsid)
コード例 #21
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_get_nonexisting_handle(self):
     ns = Namespace()
     handle = ns.get_handle(".something.totally.new", create_nodes=True)
     assert handle.get('.').nsid.nsid == ".something.totally.new"
コード例 #22
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_add_root_node(self):
     ns = Namespace()
     with self.assertRaises(NamespaceCollisionError):
         ns.add_exactly_one('.')
コード例 #23
0
ファイル: test_namespace.py プロジェクト: jl2501/thewired
 def test_get_nonexisting_handle_fail(self):
     ns = Namespace()
     with self.assertRaises(NamespaceLookupError):
         handle = ns.get_handle(".something.totally.new")
コード例 #24
0

@pytest.fixture
def mock_attribute_map():
    def mock_provider_callable():
        print("mocked provider called!")
        return "just a value to return"

    return {
        "attribute_1": "a value for attribute_1",
        "attribute_2": "a.mock.provider.namespace.nsid",
        "attribute_3": mock_provider_callable
    }


NS = Namespace()


def test_SecondLife_instantation(mock_attribute_map):
    MapNode = SecondLifeNode(nsid=".test.nsid.string",
                             namespace=NS,
                             secondlife=mock_attribute_map)
    assert str(MapNode.nsid) == '.test.nsid.string'
    assert MapNode._secondlife.keys() == mock_attribute_map.keys()


def test_SecondLife_map1(mock_attribute_map):
    MapNode = SecondLifeNode(nsid=".test.nsid.string",
                             namespace=NS,
                             secondlife=mock_attribute_map)
    assert MapNode.attribute_1 == mock_attribute_map.get('attribute_1')
コード例 #25
0
def test_NamespaceConfigParser_instantiation_with_node_factory_override_2():
    ns = Namespace(default_node_factory=NamespaceNodeBaseSubclass)
    nscp = NamespaceConfigParser(node_factory=ns.add)
    new_node = nscp.new_node(nsid='.test')[0]
    assert (isinstance(new_node, NamespaceNodeBaseSubclass))