add tests

This commit is contained in:
2019-02-23 18:42:35 +01:00
parent 7df506a754
commit d23e1d7641

25
tests/test.py Normal file
View File

@@ -0,0 +1,25 @@
import unittest
import materials
import json
import shlex
import subprocess
class TestGet(unittest.TestCase):
def test_property(self):
self.assertEqual(materials.get_value(json.loads('{"rho": 2.5}'), "rho"), 2.5, "Should be 6")
def test_property_nested(self):
self.assertEqual(materials.get_value(json.loads('{"node": {"rho": 2.5}}'), "node/rho"), 2.5, "Should be 6")
class TestCLI(unittest.TestCase):
def test_property(self):
cmd = shlex.split("materials get Al -r")
output = subprocess.check_output(cmd).decode('utf-8').strip()
self.assertEqual(output, '2.6989 g/cm³')
if __name__ == '__main__':
unittest.main()