Skip to content

Commit

Permalink
Fix test naming (dmlc#4023)
Browse files Browse the repository at this point in the history
Co-authored-by: Mufei Li <[email protected]>
  • Loading branch information
nv-dlasalle and mufeili authored May 23, 2022
1 parent 7c598aa commit 1425150
Show file tree
Hide file tree
Showing 33 changed files with 285 additions and 295 deletions.
8 changes: 4 additions & 4 deletions tests/compute/test_apply_edges_hetero.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import unittest, pytest
from dgl import DGLError
import test_utils
from test_utils import parametrize_dtype, get_cases
from test_utils import parametrize_idtype, get_cases
from scipy.sparse import rand

rfuncs = {'sum': fn.sum, 'max': fn.max, 'min': fn.min, 'mean': fn.mean}
Expand Down Expand Up @@ -39,7 +39,7 @@ def create_test_heterograph(idtype):
return g


@parametrize_dtype
@parametrize_idtype
def test_unary_copy_u(idtype):
def _test(mfunc):

Expand Down Expand Up @@ -92,7 +92,7 @@ def _print_error(a, b):
_test(fn.copy_u)


@parametrize_dtype
@parametrize_idtype
def test_unary_copy_e(idtype):
def _test(mfunc):

Expand Down Expand Up @@ -148,7 +148,7 @@ def _print_error(a, b):
_test(fn.copy_e)


@parametrize_dtype
@parametrize_idtype
def test_binary_op(idtype):
def _test(lhs, rhs, binary_op):

Expand Down
32 changes: 16 additions & 16 deletions tests/compute/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dgl import DGLGraph
from collections import defaultdict as ddict
import unittest
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype

D = 5
reduce_msg_shapes = set()
Expand Down Expand Up @@ -89,7 +89,7 @@ def generate_graph(idtype, grad=False):
def test_compatible():
g = generate_graph_old()

@parametrize_dtype
@parametrize_idtype
def test_batch_setter_getter(idtype):
def _pfc(x):
return list(F.zerocopy_to_numpy(x)[:,0])
Expand Down Expand Up @@ -159,7 +159,7 @@ def _pfc(x):
v = F.tensor([6, 9, 7], g.idtype)
assert _pfc(g.edges[u, v].data['l']) == [1.0, 1.0, 0.0]

@parametrize_dtype
@parametrize_idtype
def test_batch_setter_autograd(idtype):
g = generate_graph(idtype, grad=True)
h1 = g.ndata['h']
Expand Down Expand Up @@ -290,7 +290,7 @@ def _check_nx_feature(nxg, nf, ef):
assert F.allclose(g.edata['h'], F.tensor([[1., 2.], [1., 2.],
[2., 3.], [2., 3.]]))

@parametrize_dtype
@parametrize_idtype
def test_apply_nodes(idtype):
def _upd(nodes):
return {'h' : nodes.data['h'] * 2}
Expand All @@ -302,7 +302,7 @@ def _upd(nodes):
g.apply_nodes(lambda nodes : {'h' : nodes.data['h'] * 0.}, u)
assert F.allclose(F.gather_row(g.ndata['h'], u), F.zeros((4, D)))

@parametrize_dtype
@parametrize_idtype
def test_apply_edges(idtype):
def _upd(edges):
return {'w' : edges.data['w'] * 2}
Expand All @@ -316,7 +316,7 @@ def _upd(edges):
eid = F.tensor(g.edge_ids(u, v))
assert F.allclose(F.gather_row(g.edata['w'], eid), F.zeros((6, D)))

@parametrize_dtype
@parametrize_idtype
def test_update_routines(idtype):
g = generate_graph(idtype)

Expand Down Expand Up @@ -353,7 +353,7 @@ def test_update_routines(idtype):
assert(reduce_msg_shapes == {(1, 8, D), (9, 1, D)})
reduce_msg_shapes.clear()

@parametrize_dtype
@parametrize_idtype
def test_update_all_0deg(idtype):
# test#1
g = dgl.graph(([1, 2, 3, 4], [0, 0, 0, 0]), idtype=idtype, device=F.ctx())
Expand Down Expand Up @@ -384,7 +384,7 @@ def _init2(shape, dtype, ctx, ids):
# should fallback to apply
assert F.allclose(new_repr, 2*old_repr)

@parametrize_dtype
@parametrize_idtype
def test_pull_0deg(idtype):
g = dgl.graph(([0], [1]), idtype=idtype, device=F.ctx())
def _message(edges):
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_dynamic_addition():
assert len(g.edata['h1']) == len(g.edata['h2'])


@parametrize_dtype
@parametrize_idtype
def test_repr(idtype):
g = dgl.graph(([0, 0, 1], [1, 2, 2]), num_nodes=10, idtype=idtype, device=F.ctx())
repr_string = g.__repr__()
Expand All @@ -460,7 +460,7 @@ def test_repr(idtype):
repr_string = g.__repr__()
print(repr_string)

@parametrize_dtype
@parametrize_idtype
def test_local_var(idtype):
g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4]), idtype=idtype, device=F.ctx())
g.ndata['h'] = F.zeros((g.number_of_nodes(), 3))
Expand Down Expand Up @@ -518,7 +518,7 @@ def foo(g):
assert F.allclose(g.edata['w'], F.tensor([[1.], [0.]]))
foo(g)

@parametrize_dtype
@parametrize_idtype
def test_local_scope(idtype):
g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4]), idtype=idtype, device=F.ctx())
g.ndata['h'] = F.zeros((g.number_of_nodes(), 3))
Expand Down Expand Up @@ -590,7 +590,7 @@ def foo(g):
assert F.allclose(g.edata['w'], F.tensor([[1.], [0.]]))
foo(g)

@parametrize_dtype
@parametrize_idtype
def test_isolated_nodes(idtype):
g = dgl.graph(([0, 1], [1, 2]), num_nodes=5, idtype=idtype, device=F.ctx())
assert g.number_of_nodes() == 5
Expand All @@ -610,7 +610,7 @@ def test_isolated_nodes(idtype):
assert g.number_of_nodes('user') == 5
assert g.number_of_nodes('game') == 7

@parametrize_dtype
@parametrize_idtype
def test_send_multigraph(idtype):
g = dgl.graph(([0, 0, 0, 2], [1, 1, 1, 1]), idtype=idtype, device=F.ctx())

Expand All @@ -636,7 +636,7 @@ def answer(*args):
assert F.allclose(new_repr[1], answer(old_repr[0], old_repr[2], old_repr[3]))
assert F.allclose(new_repr[[0, 2]], F.zeros((2, 5)))

@parametrize_dtype
@parametrize_idtype
def test_issue_1088(idtype):
# This test ensures that message passing on a heterograph with one edge type
# would not crash (GitHub issue #1088).
Expand All @@ -645,7 +645,7 @@ def test_issue_1088(idtype):
g.nodes['U'].data['x'] = F.randn((3, 3))
g.update_all(fn.copy_u('x', 'm'), fn.sum('m', 'y'))

@parametrize_dtype
@parametrize_idtype
def test_degree_bucket_edge_ordering(idtype):
import dgl.function as fn
g = dgl.graph(
Expand All @@ -658,7 +658,7 @@ def reducer(nodes):
return {'n': F.sum(nodes.mailbox['eid'], 1)}
g.update_all(fn.copy_e('eid', 'eid'), reducer)

@parametrize_dtype
@parametrize_idtype
def test_issue_2484(idtype):
import dgl.function as fn
g = dgl.graph(([0, 1, 2], [1, 2, 3]), idtype=idtype, device=F.ctx())
Expand Down
22 changes: 11 additions & 11 deletions tests/compute/test_batched_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import backend as F
import unittest
from test_utils import parametrize_dtype
from test_utils import parametrize_idtype

def tree1(idtype):
"""Generate a tree
Expand Down Expand Up @@ -42,7 +42,7 @@ def tree2(idtype):
g.edata['h'] = F.randn((4, 10))
return g

@parametrize_dtype
@parametrize_idtype
def test_batch_unbatch(idtype):
t1 = tree1(idtype)
t2 = tree2(idtype)
Expand All @@ -60,7 +60,7 @@ def test_batch_unbatch(idtype):
assert F.allclose(t2.ndata['h'], tt2.ndata['h'])
assert F.allclose(t2.edata['h'], tt2.edata['h'])

@parametrize_dtype
@parametrize_idtype
def test_batch_unbatch1(idtype):
t1 = tree1(idtype)
t2 = tree2(idtype)
Expand All @@ -81,7 +81,7 @@ def test_batch_unbatch1(idtype):
assert F.allclose(t2.edata['h'], s3.edata['h'])

@unittest.skipIf(dgl.backend.backend_name == "tensorflow", reason="TF doesn't support inplace update")
@parametrize_dtype
@parametrize_idtype
def test_batch_unbatch_frame(idtype):
"""Test module of node/edge frames of batched/unbatched DGLGraphs.
Also address the bug mentioned in https://github.com/dmlc/dgl/issues/1475.
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_batch_unbatch_frame(idtype):
assert F.allclose(_g2.ndata['h'], F.zeros((N2, D)))
assert F.allclose(_g2.edata['h'], F.zeros((E2, D)))

@parametrize_dtype
@parametrize_idtype
def test_batch_unbatch2(idtype):
# test setting/getting features after batch
a = dgl.graph(([], [])).astype(idtype).to(F.ctx())
Expand All @@ -133,7 +133,7 @@ def test_batch_unbatch2(idtype):
assert F.allclose(c.ndata['h'], F.ones((7, 1)))
assert F.allclose(c.edata['w'], F.ones((5, 1)))

@parametrize_dtype
@parametrize_idtype
def test_batch_send_and_recv(idtype):
t1 = tree1(idtype)
t2 = tree2(idtype)
Expand All @@ -150,7 +150,7 @@ def test_batch_send_and_recv(idtype):
assert F.asnumpy(t1.ndata['h'][1]) == 7
assert F.asnumpy(t2.ndata['h'][4]) == 2

@parametrize_dtype
@parametrize_idtype
def test_batch_propagate(idtype):
t1 = tree1(idtype)
t2 = tree2(idtype)
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_batch_propagate(idtype):
assert F.asnumpy(t1.ndata['h'][0]) == 9
assert F.asnumpy(t2.ndata['h'][1]) == 5

@parametrize_dtype
@parametrize_idtype
def test_batched_edge_ordering(idtype):
g1 = dgl.graph(([], [])).astype(idtype).to(F.ctx())
g1.add_nodes(6)
Expand All @@ -195,7 +195,7 @@ def test_batched_edge_ordering(idtype):
r2 = g1.edata['h'][g1.edge_id(4, 5)]
assert F.array_equal(r1, r2)

@parametrize_dtype
@parametrize_idtype
def test_batch_no_edge(idtype):
g1 = dgl.graph(([], [])).astype(idtype).to(F.ctx())
g1.add_nodes(6)
Expand All @@ -207,7 +207,7 @@ def test_batch_no_edge(idtype):
g3.add_nodes(1) # no edges
g = dgl.batch([g1, g3, g2]) # should not throw an error

@parametrize_dtype
@parametrize_idtype
def test_batch_keeps_empty_data(idtype):
g1 = dgl.graph(([], [])).astype(idtype).to(F.ctx())
g1.ndata["nh"] = F.tensor([])
Expand Down Expand Up @@ -248,7 +248,7 @@ def _get_subgraph_batch_info(keys, induced_indices_arr, batch_num_objs):
ret[key] = F.tensor(new_batch_num_objs, dtype=F.dtype(batch_num_objs))
return ret

@parametrize_dtype
@parametrize_idtype
def test_set_batch_info(idtype):
ctx = F.ctx()

Expand Down
16 changes: 8 additions & 8 deletions tests/compute/test_batched_heterograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from dgl.base import ALL
from utils import parametrize_dtype
from test_utils import parametrize_idtype
from test_utils import check_graph_equal, get_cases


Expand Down Expand Up @@ -46,7 +46,7 @@ def check_equivalence_between_heterographs(g1, g2, node_attrs=None, edge_attrs=N


@pytest.mark.parametrize('gs', get_cases(['two_hetero_batch']))
@parametrize_dtype
@parametrize_idtype
def test_topology(gs, idtype):
"""Test batching two DGLHeteroGraphs where some nodes are isolated in some relations"""
g1, g2 = gs
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_topology(gs, idtype):
assert bg.batch_size == bg_local.batch_size


@parametrize_dtype
@parametrize_idtype
def test_batching_batched(idtype):
"""Test batching a DGLHeteroGraph and a BatchedDGLHeteroGraph."""
g1 = dgl.heterograph({
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_batching_batched(idtype):
check_equivalence_between_heterographs(g3, g6)


@parametrize_dtype
@parametrize_idtype
def test_features(idtype):
"""Test the features of batched DGLHeteroGraphs"""
g1 = dgl.heterograph({
Expand Down Expand Up @@ -243,7 +243,7 @@ def test_features(idtype):


@unittest.skipIf(F.backend_name == 'mxnet', reason="MXNet does not support split array with zero-length segment.")
@parametrize_dtype
@parametrize_idtype
def test_empty_relation(idtype):
"""Test the features of batched DGLHeteroGraphs"""
g1 = dgl.heterograph({
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_empty_relation(idtype):
dgl.batch([g1, g2])


@parametrize_dtype
@parametrize_idtype
def test_unbatch2(idtype):
# batch 3 graphs but unbatch to 2
g1 = dgl.graph(([0, 1, 2], [1, 2, 3]), idtype=idtype, device=F.ctx())
Expand All @@ -333,7 +333,7 @@ def test_unbatch2(idtype):
check_graph_equal(g3, gg3)


@parametrize_dtype
@parametrize_idtype
def test_slice_batch(idtype):
g1 = dgl.heterograph({
('user', 'follows', 'user'): ([0, 1], [1, 2]),
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_slice_batch(idtype):
assert F.allclose(g_i.edges[ety].data[feat], g_slice.edges[ety].data[feat])


@parametrize_dtype
@parametrize_idtype
def test_batch_keeps_empty_data(idtype):
g1 = dgl.heterograph({("a", "to", "a"): ([], [])}
).astype(idtype).to(F.ctx())
Expand Down
Loading

0 comments on commit 1425150

Please sign in to comment.