Commit bb68e812 authored by lavocat's avatar lavocat
Browse files

Implement unit tests

This commit provide the structure for unit tests.
To add a test, just create a new file in the test folder named
test_whatever.py
parent 896e14b6
.cache
*.egg*
dist
launch.sh
......
......@@ -83,3 +83,9 @@ SendEnv PYTHONPATH
AcceptEnv PATH
AcceptEnv PYTHONPATH
Ensure no max session is set.
# Unit tests
```
python3 setup.py test
```
[aliases]
test=pytest
......@@ -22,7 +22,8 @@ setup(
keywords='taktuk parallel fork InSitu',
packages=find_packages(),
install_requires=['pyzmq', 'pexpect'],
setup_requires=['pytest-runner'],
install_requires=['pytest', 'pyzmq', 'pexpect'],
entry_points={
'console_scripts': [
......
import pytest
from yggdrasil.erebor.encoder import MPIDecoder
def test_mpi_decoder():
d = MPIDecoder()
l = ["a", "b", "cd", "efghij", "a"]
e = d.pack(*l)
assert(d.unpack(e) == l)
import pytest
from yggdrasil.isengard.isengardc import Helper
def test_helper():
helper = Helper()
#print("node1")
assert(" ".join(helper.build_list("node1")) == "node1")
#print("\nnode[19]")
assert(" ".join(helper.build_list("node[19]")) == "node19")
#print("\nnode[1-3]")
assert(" ".join(helper.build_list("node[1-3]")) == "node1 node2 node3")
#print("\nnode[1-3],otherhost/node2")
assert(" ".join(helper.build_list("node[1-3],otherhost/node2")) == "node1 node3 otherhost")
#print("\nnode[1-3,5]part[a-b]/node[3-5]parta,node1partb")
assert(" ".join(helper.build_list("node[1-3,5]part[a-b]/node[3-5]parta,node1partb")) == "node1parta node2parta node2partb node3partb node5partb")
#print("\nA,B,C,D,E,F")
assert(" ".join(helper.build_list("A,B,C,D,E,F")) == "A B C D E F")
a = (helper.compose([1]))
assert(a[0] == "1")
b = (helper.compose([1,2,3,4]))
assert(b[0] == "1-4")
c = (helper.compose([1,4,5,10]))
assert(c[0] == "1")
assert(c[1] == "4-5")
assert(c[2] == "10")
d = (helper.compose([1,4,5,6,10,11,12]))
assert(d[0] == "1")
assert(d[1] == "4-6")
assert(d[2] == "10-12")
assert(helper.build_list("["+",".join(a)+"]") == ["1"])
assert(helper.build_list("["+",".join(b)+"]") == ["1","2","3","4"])
assert(helper.build_list("["+",".join(c)+"]") == ["1","4","5","10"])
assert(helper.build_list("["+",".join(d)+"]") == ["1","4","5","6","10","11","12"])
#!/usr/bin/env python3
import sys
import struct
from ..isengard import consts
......@@ -26,12 +25,3 @@ class MPIDecoder:
packed += struct.pack('>I', len(field))
packed += bytes(field, consts.encoding)
return packed;
def main(argv):
d = MPIDecoder()
l = ["a", "b", "cd", "efghij", "a"]
e = d.pack(*l)
assert(d.unpack(e) == l)
if __name__ == "__main__":
sys.exit(main(sys.argv))
#!/usr/bin/env python3.5
import sys
from isengard.isengardc import Helper
def main(argv):
helper = Helper()
print("node1")
print(" ".join(helper.build_list("node1")) == "node1")
print("\nnode[19]")
print(" ".join(helper.build_list("node[19]")) == "node19")
print("\nnode[1-3]")
print(" ".join(helper.build_list("node[1-3]")) == "node1 node2 node3")
print("\nnode[1-3],otherhost/node2")
print(" ".join(helper.build_list("node[1-3],otherhost/node2")) == "node1 node3 otherhost")
print("\nnode[1-3,5]part[a-b]/node[3-5]parta,node1partb")
print(" ".join(helper.build_list("node[1-3,5]part[a-b]/node[3-5]parta,node1partb")) == "node1parta node2parta node2partb node3partb node5partb")
print("\nA,B,C,D,E,F")
print(" ".join(helper.build_list("A,B,C,D,E,F")) == "A B C D E F")
print(helper.compose([1]))
print(helper.compose([1,2,3,4]))
print(helper.compose([1,4,5,10]))
print(helper.compose([1,4,5,6,10,11,12]))
print(helper.build_list("["+",".join(helper.compose([1]))+"]"))
print(helper.build_list("["+",".join(helper.compose([1,2,3,4]))+"]"))
print(helper.build_list("["+",".join(helper.compose([1,4,5,10]))+"]"))
print(helper.build_list("["+",".join(helper.compose([1,4,5,6,10,11,12]))+"]"))
if __name__ == "__main__":
sys.exit(main(sys.argv))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment