Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshrinet committed Mar 26, 2024
1 parent f2dcc05 commit c132be6
Show file tree
Hide file tree
Showing 146 changed files with 14 additions and 1,118 deletions.
1 change: 0 additions & 1 deletion binder/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions binder/environment.yml

This file was deleted.

124 changes: 0 additions & 124 deletions binder/ex1-unboundedFlow.ipynb

This file was deleted.

148 changes: 0 additions & 148 deletions binder/ex2-flowPlaneSurface.ipynb

This file was deleted.

105 changes: 0 additions & 105 deletions binder/ex3-crystalNucleation.ipynb

This file was deleted.

152 changes: 0 additions & 152 deletions binder/ex4-crystallization.ipynb

This file was deleted.

103 changes: 0 additions & 103 deletions binder/ex5-phoreticField.ipynb

This file was deleted.

121 changes: 0 additions & 121 deletions binder/ex6-arrestedCluster.ipynb

This file was deleted.

261 changes: 0 additions & 261 deletions binder/ex8-holographicTrap.ipynb

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
109 changes: 14 additions & 95 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,6 @@
ignoreFlag=True # change to False if not to ignore


def run_notebook_tests(path, recursive=False):
"""
Runs Jupyter notebook tests. Exits if they fail.
"""
basepath = os.path.dirname(__file__)
nbpath = os.path.abspath(os.path.join(basepath, "..", path))
'''
Ignore notebooks which take longer or have deliberate errors,
but check they still exists
'''
os.chdir('../examples/')
cwd =os.getcwd()
ignore_list = [os.path.join(cwd, 'ex3-crystalNucleation.ipynb'),
os.path.join(cwd, 'ex4-crystallization.ipynb'),
os.path.join(cwd, 'ex6-arrestedCluster.ipynb'),
os.path.join(cwd, 'ex7-benchmark.ipynb'),
os.path.join(cwd, 'others/abp/active_brownian_2D.ipynb'),
]

for ignored_book in ignore_list:
if not os.path.isfile(ignored_book):
raise Exception('Ignored notebook not found: ' + ignored_book)

# Scan and run
print('Testing notebooks')
ok = True
for notebook, cwd in list_notebooks(nbpath, recursive, ignore_list):
os.chdir(cwd) # necessary for relative imports in notebooks
ok &= test_notebook(notebook)
# print(notebook)
if not ok:
print('\nErrors encountered in notebooks')
sys.exit(1)
print('\nOK')


def list_notebooks(root, recursive=False, ignore_list=None, notebooks=None):
"""
Returns a list of all notebooks in a directory.
"""
if notebooks is None:
notebooks = []
if ignore_list is None or ignoreFlag==False:
ignore_list = []
try:
for filename in os.listdir(root):
path = os.path.join(root, filename)
cwd = os.path.dirname(path)
if path in ignore_list:
print('Skipping ignored notebook: ' + path)
continue

# Add notebooks
if os.path.splitext(path)[1] == '.ipynb':
notebooks.append((path,cwd))

# Recurse into subdirectories
elif recursive and os.path.isdir(path):
# Ignore hidden directories
if filename[:1] == '.':
continue
list_notebooks(path, recursive, ignore_list, notebooks)
except NotADirectoryError:
path = root
cwd = os.path.dirname(path)
return [(path,cwd)]

return notebooks


def test_notebook(path):
"""
Expand Down Expand Up @@ -158,29 +89,17 @@ def export_notebook(ipath, opath):
os.chmod(opath, 0o775)


if __name__ == '__main__':
# Set up argument parsing
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
parser = argparse.ArgumentParser(
description='Run notebook unit tests for PyStokes.',
)
# Unit tests
parser.add_argument(
'--path', default = '.',
help='Run specific notebook or folder containing notebooks',)
parser.add_argument(
'--recursive', default = True, type=str2bool,
help='Wheither or not subfolders are searched',)

# Parse!
args = parser.parse_args()
print(args)
run_notebook_tests(args.path, recursive=args.recursive)
cwd0 =os.getcwd()
os.chdir('../examples/')
cwd =os.getcwd()

path1 = cwd+'/ex1-unboundedFlow.ipynb'
path2 = cwd+'/ex2-flowPlaneSurface.ipynb'
path3 = cwd+'/ex5-phoreticField.ipynb'
path4 = cwd+'/ex8-holographicTrap.ipynb'
path5 = cwd+'/ex3-crystalNucleation.ipynb'
test_notebook(path1)
test_notebook(path2)
test_notebook(path3)
test_notebook(path4)
test_notebook(path5)

0 comments on commit c132be6

Please sign in to comment.