Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainKadar committed Sep 26, 2024
1 parent 7afb007 commit 901baaa
Show file tree
Hide file tree
Showing 63 changed files with 33 additions and 70 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified StructuralGT/pytest/__pycache__/network_factory.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 7 additions & 7 deletions StructuralGT/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from StructuralGT import networks
from StructuralGT.networks import Network
import numpy as np
import matplotlib.pyplot as plt
import pytest
Expand All @@ -20,7 +20,7 @@

@pytest.fixture(scope="session")
def fibrous(weight_type=None):
ANF = networks.Network(_path + '/pytest/data/ANF', prefix='slice', dim=3)
ANF = Network('StructuralGT/pytest/data/ANF', prefix='slice', dim=3)
ANF.binarize(options=anf_options)
ANF.img_to_skel(crop=[200,300,200,300, 1, 3])
ANF.set_graph(weight_type=weight_type)
Expand All @@ -29,7 +29,7 @@ def fibrous(weight_type=None):

@pytest.fixture(scope="session")
def conductive():
AgNWN = networks.Network(_path + '/pytest/data/AgNWN', prefix='slice')
AgNWN = Network('StructuralGT/pytest/data/AgNWN', prefix='slice')
AgNWN.binarize(options=agnwn_options)
AgNWN.img_to_skel(crop=[149, 868, 408, 800])
AgNWN.set_graph(weight_type=['FixedWidthConductance'], R_j=10, rho_dim=2)
Expand Down Expand Up @@ -85,10 +85,10 @@ def main(aligned=False, num_sticks=210, stick_length=300.0):
@pytest.fixture(scope="session")
def random_stick():
fig = main(aligned=False)
img_path = _path + '/pytest/data/Random'
img_path = 'StructuralGT/pytest/data/Random'
fig.savefig(img_path + '/slice0000.png',bbox_inches='tight', dpi=300)

RS = networks.Network(img_path, prefix='slice')
RS = Network(img_path, prefix='slice')
RS.binarize(options=stick_options)
RS.img_to_skel()
RS.set_graph(sub=False)
Expand All @@ -98,10 +98,10 @@ def random_stick():
@pytest.fixture(scope="session")
def aligned_stick():
fig = main(aligned=True)
img_path = _path + '/pytest/data/Aligned'
img_path = 'StructuralGT/pytest/data/Aligned'
fig.savefig(img_path + '/slice0000.png',bbox_inches='tight', dpi=300)

RS = networks.Network(img_path, prefix='slice')
RS = Network(img_path, prefix='slice')
RS.binarize(options=stick_options)
RS.img_to_skel()
RS.set_graph(sub=False)
Expand Down
Binary file added StructuralGT/pytest/data/.DS_Store
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions StructuralGT/pytest/data/ANF/Binarized/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "StructuralGT/pytest/data/ANF/Binarized", "_2d": "True", "dim": "2", "cropper": "(200, 300, 200, 300)"}
Binary file modified StructuralGT/pytest/data/ANF/Binarized/skel.gsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified StructuralGT/pytest/data/AgNWN/.DS_Store
Binary file not shown.
Binary file modified StructuralGT/pytest/data/AgNWN/Binarized/connected_skel.gsd
Binary file not shown.
Binary file modified StructuralGT/pytest/data/AgNWN/Binarized/network.gsd
Binary file not shown.
2 changes: 1 addition & 1 deletion StructuralGT/pytest/data/AgNWN/Binarized/network.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"stack_dir": "/Users/alaink/Software/StructuralGT/StructuralGT/pytest/data/AgNWN/Binarized", "_2d": "True", "dim": "2", "cropper": "(408, 800, 149, 868)"}
{"stack_dir": "StructuralGT/pytest/data/AgNWN/Binarized", "_2d": "True", "dim": "2", "cropper": "(408, 800, 149, 868)"}
Binary file modified StructuralGT/pytest/data/AgNWN/Binarized/skel.gsd
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions StructuralGT/pytest/data/Aligned/Binarized/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "StructuralGT/pytest/data/Aligned/Binarized", "_2d": "True", "dim": "2", "cropper": "None"}
Binary file modified StructuralGT/pytest/data/Aligned/Binarized/skel.gsd
Binary file not shown.
Binary file modified StructuralGT/pytest/data/Aligned/Binarized/slice0000.tiff
Binary file not shown.
Binary file modified StructuralGT/pytest/data/Aligned/slice0000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1 change: 1 addition & 0 deletions StructuralGT/pytest/data/Random/Binarized/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "StructuralGT/pytest/data/Random/Binarized", "_2d": "True", "dim": "2", "cropper": "None"}
Binary file modified StructuralGT/pytest/data/Random/Binarized/skel.gsd
Binary file not shown.
Binary file modified StructuralGT/pytest/data/Random/Binarized/slice0000.tiff
Binary file not shown.
Binary file modified StructuralGT/pytest/data/Random/slice0000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1 change: 1 addition & 0 deletions StructuralGT/pytest/data/Small/Binarized/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "StructuralGT/pytest/data/Small/Binarized", "_2d": "True", "dim": "2", "cropper": "None"}
Binary file modified StructuralGT/pytest/data/Small/Binarized/skel.gsd
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions StructuralGT/pytest/graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "/Users/alaink/miniconda3/envs/SGTE-dev/lib/python3.10/site-packages/StructuralGT-0.0.1-py3.10-macosx-11.0-arm64.egg/StructuralGT/pytest/data/Small/Binarized", "depth": "None", "_2d": "True", "dim": "2", "cropper": "None"}
1 change: 1 addition & 0 deletions StructuralGT/pytest/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stack_dir": "/Users/alaink/miniconda3/envs/SGTE-dev/lib/python3.10/site-packages/StructuralGT-0.0.1-py3.10-macosx-11.0-arm64.egg/StructuralGT/pytest/data/Small/Binarized", "depth": "None", "_2d": "True", "dim": "2", "cropper": "(50, 50)"}
11 changes: 11 additions & 0 deletions StructuralGT/pytest/sbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import igraph

G1 = igraph.Graph.K_Regular(10, 2)
G2 = igraph.Graph.K_Regular(10, 2)

def graph_function(G):
print(G.degree())

graph_function(list(G1,G2))


2 changes: 0 additions & 2 deletions StructuralGT/pytest/test_AverageNodalConnectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy.testing as npt
import numpy as np

"""TODO-FIX
class TestAverageNodalConnectivity:
def test(self, fibrous):
#Obtain a connected graph
Expand All @@ -29,4 +28,3 @@ def test(self, fibrous):
np.mean(np.asarray(vals)),
rtol=1e-2,
)
"""
25 changes: 8 additions & 17 deletions StructuralGT/pytest/test_Networks.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
from StructuralGT.networks import Network, ParticleNetwork, Graph
import StructuralGT

from StructuralGT import error
import pytest
import shutil
import os

import options

_path = StructuralGT.__path__[0]
Small_path = _path + '/pytest/data/Small/' #2D directory with single image
AgNWN_path = _path + '/pytest/data/AgNWN/' #2D directory with several images
ANF_path = _path + '/pytest/data/ANF/' #3D directory
Small_path = 'StructuralGT/pytest/data/Small/' #2D directory with single image
AgNWN_path = 'StructuralGT/pytest/data/AgNWN/' #2D directory with several images
ANF_path = 'StructuralGT/pytest/data/ANF/' #3D directory

class TestNetwork:

"""
CURRENTLY BROKEN - WILL FIX LATER
def test_3d_constructor(self):

with pytest.raises(ValueError):
with pytest.raises(error.ImageDirectoryError):
testNetwork = Network(ANF_path, dim=3, prefix='wrong_prefix')

with pytest.raises(ValueError):
testNetwork = Network(ANF_path, dim=3, depth=[283,282])
testNetwork = Network(ANF_path, dim=3, prefix='slice', depth=[3,287])
assert len(testNetwork.image_stack)==6
#assert len(testNetwork.image_stack)==6

testNetwork = Network(ANF_path, dim=3, depth=[281,288])

testNetwork = Network(ANF_path, dim=3, prefix='slice')
assert len(testNetwork.image_stack)==12

return testNetwork
"""
#return testNetwork uncomment if 3D network becomes required as a fixture in other tests

@pytest.fixture
def test_2d_constructor(self):

with pytest.raises(ImageDirectoryError):
with pytest.raises(error.ImageDirectoryError):
testNetwork = Network(AgNWN_path, prefix='wrong_prefix')

with pytest.raises(UserWarning):
Expand Down
43 changes: 0 additions & 43 deletions StructuralGT/pytest/test_Structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,46 +128,3 @@ def test_compute(self, conductive):

#TODO: Add tests


"""
class TestWeightedStructural:
@pytest.fixture
def test_compute(self):
#Obtain an unweighted connected graph
testNetwork = conductive(weight_type=['Length'])
testGraph = testNetwork.graph.to_networkx()
#Instantiate a compute module and run calculation
ComputeModule = Structural(weight_type='Length')
ComputeModule.compute(testNetwork)
return ComputeModule, testGraph
def test_diameter(self, test_compute):
ComputeModule, testGraph = test_compute
npt.assert_allclose(
ComputeModule.diameter,
diameter(testGraph, weight='Length'),
atol=1e-2,
)
def test_betweenness(self, test_compute):
ComputeModule, testGraph = test_compute
npt.assert_allclose(
ComputeModule.betweenness,
np.fromiter(betweenness_centrality(testGraph,
weight='Length').values(),
dtype=float),
atol=1e-2,
)
def test_closenness(self, test_compute):
ComputeModule, testGraph = test_compute
npt.assert_allclose(
ComputeModule.closeness,
np.fromiter(closeness_centrality(testGraph,
distance='Length').values(),
dtype=float),
atol=1e-2,
)
"""

0 comments on commit 901baaa

Please sign in to comment.