Skip to content

Commit

Permalink
Adding tests, caught some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgostick committed May 9, 2019
1 parent d12aa23 commit 8911548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openpnm/utils/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,14 @@ def row(self, name):
for row in self.grid.table_data:
if row[0].startswith(name):
return row
else:
raise ValueError(name + 'is not in list')

def col(self, name):
# Find column number
index = self.table_data[0].index(name)
index = self.grid.table_data[0].index(name)
col = []
for row in self.grid.data_table:
for row in self.grid.table_data:
col.append(row[index])
return col

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/utils/ProjectTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ def test_grid_printing(self):
'└────────────┴──────────────┴──────────────┘\n'
assert print(self.proj.grid) == print(s)

def test_grid_access(self):
g = self.proj.grid
with pytest.raises(ValueError):
g.col(self.geo1.name)
r = g.row(self.geo1.name)
assert r == ['geo_01', 'phys_01', 'phys_03']
with pytest.raises(ValueError):
g.row(self.phase1.name)
c = g.col(self.phase1.name)
assert c == ['phase_01', 'phys_01', 'phys_02']
c = g.col(self.phase2.name)
assert c == ['phase_02', 'phys_03', 'phys_04']

def test_purge_geom_shallow(self):
proj = self.ws.copy_project(self.net.project)
net = proj.network
Expand Down

0 comments on commit 8911548

Please sign in to comment.