summaryrefslogtreecommitdiff
path: root/networkx/utils/tests
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2020-12-07 18:03:58 -0800
committerGitHub <noreply@github.com>2020-12-07 21:03:58 -0500
commit831705dba1a2536ecf3b874da3510bead62ff489 (patch)
treef55143be2ef0b48b2901a721e08e1107a3f9db5e /networkx/utils/tests
parentb8ca636525e12f13a491c3d738c965fe1ce7851c (diff)
downloadnetworkx-831705dba1a2536ecf3b874da3510bead62ff489.tar.gz
Standard imports (#4401)
* Standardize pytest imports * Standardize numpy/scipy imports * Document import style * Fix * More * Fix matplotlib imports * Revert changes to tests * Motivate import policy Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fix missed imports * Standard np.testing use Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'networkx/utils/tests')
-rw-r--r--networkx/utils/tests/test_misc.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/networkx/utils/tests/test_misc.py b/networkx/utils/tests/test_misc.py
index b20648cb..4abb7ce6 100644
--- a/networkx/utils/tests/test_misc.py
+++ b/networkx/utils/tests/test_misc.py
@@ -127,15 +127,13 @@ def test_make_str_with_unicode():
class TestNumpyArray:
@classmethod
def setup_class(cls):
- global numpy
- global assert_allclose
- numpy = pytest.importorskip("numpy")
- assert_allclose = numpy.testing.assert_allclose
+ global np
+ np = pytest.importorskip("numpy")
def test_numpy_to_list_of_ints(self):
- a = numpy.array([1, 2, 3], dtype=numpy.int64)
- b = numpy.array([1.0, 2, 3])
- c = numpy.array([1.1, 2, 3])
+ a = np.array([1, 2, 3], dtype=np.int64)
+ b = np.array([1.0, 2, 3])
+ c = np.array([1.1, 2, 3])
assert type(make_list_of_ints(a)) == list
assert make_list_of_ints(b) == list(b)
B = make_list_of_ints(b)
@@ -145,46 +143,46 @@ class TestNumpyArray:
def test_dict_to_numpy_array1(self):
d = {"a": 1, "b": 2}
a = dict_to_numpy_array1(d, mapping={"a": 0, "b": 1})
- assert_allclose(a, numpy.array([1, 2]))
+ np.testing.assert_allclose(a, np.array([1, 2]))
a = dict_to_numpy_array1(d, mapping={"b": 0, "a": 1})
- assert_allclose(a, numpy.array([2, 1]))
+ np.testing.assert_allclose(a, np.array([2, 1]))
a = dict_to_numpy_array1(d)
- assert_allclose(a.sum(), 3)
+ np.testing.assert_allclose(a.sum(), 3)
def test_dict_to_numpy_array2(self):
d = {"a": {"a": 1, "b": 2}, "b": {"a": 10, "b": 20}}
mapping = {"a": 1, "b": 0}
a = dict_to_numpy_array2(d, mapping=mapping)
- assert_allclose(a, numpy.array([[20, 10], [2, 1]]))
+ np.testing.assert_allclose(a, np.array([[20, 10], [2, 1]]))
a = dict_to_numpy_array2(d)
- assert_allclose(a.sum(), 33)
+ np.testing.assert_allclose(a.sum(), 33)
def test_dict_to_numpy_array_a(self):
d = {"a": {"a": 1, "b": 2}, "b": {"a": 10, "b": 20}}
mapping = {"a": 0, "b": 1}
a = dict_to_numpy_array(d, mapping=mapping)
- assert_allclose(a, numpy.array([[1, 2], [10, 20]]))
+ np.testing.assert_allclose(a, np.array([[1, 2], [10, 20]]))
mapping = {"a": 1, "b": 0}
a = dict_to_numpy_array(d, mapping=mapping)
- assert_allclose(a, numpy.array([[20, 10], [2, 1]]))
+ np.testing.assert_allclose(a, np.array([[20, 10], [2, 1]]))
a = dict_to_numpy_array2(d)
- assert_allclose(a.sum(), 33)
+ np.testing.assert_allclose(a.sum(), 33)
def test_dict_to_numpy_array_b(self):
d = {"a": 1, "b": 2}
mapping = {"a": 0, "b": 1}
a = dict_to_numpy_array(d, mapping=mapping)
- assert_allclose(a, numpy.array([1, 2]))
+ np.testing.assert_allclose(a, np.array([1, 2]))
a = dict_to_numpy_array1(d)
- assert_allclose(a.sum(), 3)
+ np.testing.assert_allclose(a.sum(), 3)
def test_pairwise():