MCPcopy
hub / github.com/dmlc/dgl / test_query

Function test_query

tests/python/common/test_heterograph.py:370–540  ·  view source on GitHub ↗
(idtype)

Source from the content-addressed store, hash-verified

368
369@parametrize_idtype
370def test_query(idtype):
371 g = create_test_heterograph(idtype)
372
373 ntypes = ["user", "game", "developer"]
374 canonical_etypes = [
375 ("user", "follows", "user"),
376 ("user", "plays", "game"),
377 ("user", "wishes", "game"),
378 ("developer", "develops", "game"),
379 ]
380 etypes = ["follows", "plays", "wishes", "develops"]
381
382 # node & edge types
383 assert set(ntypes) == set(g.ntypes)
384 assert set(etypes) == set(g.etypes)
385 assert set(canonical_etypes) == set(g.canonical_etypes)
386
387 # metagraph
388 mg = g.metagraph()
389 assert set(g.ntypes) == set(mg.nodes)
390 etype_triplets = [(u, v, e) for u, v, e in mg.edges(keys=True)]
391 assert set(
392 [
393 ("user", "user", "follows"),
394 ("user", "game", "plays"),
395 ("user", "game", "wishes"),
396 ("developer", "game", "develops"),
397 ]
398 ) == set(etype_triplets)
399 for i in range(len(etypes)):
400 assert g.to_canonical_etype(etypes[i]) == canonical_etypes[i]
401
402 def _test(g):
403 # number of nodes
404 assert [g.num_nodes(ntype) for ntype in ntypes] == [3, 2, 2]
405
406 # number of edges
407 assert [g.num_edges(etype) for etype in etypes] == [2, 4, 2, 2]
408
409 # has_nodes
410 for ntype in ntypes:
411 n = g.num_nodes(ntype)
412 for i in range(n):
413 assert g.has_nodes(i, ntype)
414 assert not g.has_nodes(n, ntype)
415 assert np.array_equal(
416 F.asnumpy(g.has_nodes([0, n], ntype)).astype("int32"), [1, 0]
417 )
418
419 assert not g.is_multigraph
420
421 for etype in etypes:
422 srcs, dsts = edges[etype]
423 for src, dst in zip(srcs, dsts):
424 assert g.has_edges_between(src, dst, etype)
425 assert F.asnumpy(g.has_edges_between(srcs, dsts, etype)).all()
426
427 srcs, dsts = negative_edges[etype]

Callers

nothing calls this directly

Calls 7

create_test_heterograph1Function · 0.85
create_test_heterographFunction · 0.70
_testFunction · 0.70
create_test_heterograph2Function · 0.70
metagraphMethod · 0.45
edgesMethod · 0.45
to_canonical_etypeMethod · 0.45

Tested by

no test coverage detected