Files
lammps/unittest/python/python-capabilities.py
Richard Berger 77d475d121 Add more tests
2020-09-11 15:48:23 -04:00

55 lines
2.0 KiB
Python

import sys,os,unittest
from lammps import lammps
class PythonCapabilities(unittest.TestCase):
def setUp(self):
machine = None
if 'LAMMPS_MACHINE_NAME' in os.environ:
machine=os.environ['LAMMPS_MACHINE_NAME']
self.lmp = lammps(name=machine, cmdargs=['-nocite', '-log','none', '-echo','screen'])
if 'LAMMPS_CMAKE_CACHE' in os.environ:
self.cmake_cache = {}
with open(os.environ['LAMMPS_CMAKE_CACHE'], 'r') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#') or line.startswith('//'): continue
parts = line.split('=')
key, value_type = parts[0].split(':')
if len(parts) > 1:
value = parts[1]
if value_type == "BOOL":
value = (value.upper() == "ON")
else:
value = None
self.cmake_cache[key] = value
def tearDown(self):
del self.lmp
def test_has_gzip_support(self):
self.assertEqual(self.lmp.has_gzip_support, self.cmake_cache['WITH_GZIP'])
def test_has_png_support(self):
self.assertEqual(self.lmp.has_png_support, self.cmake_cache['WITH_PNG'])
def test_has_jpeg_support(self):
self.assertEqual(self.lmp.has_jpeg_support, self.cmake_cache['WITH_JPEG'])
def test_has_ffmpeg_support(self):
self.assertEqual(self.lmp.has_ffmpeg_support, self.cmake_cache['WITH_FFMPEG'])
def test_installed_packages(self):
installed_packages = self.lmp.installed_packages
selected_packages = [key[4:] for key in self.cmake_cache.keys() if not key.startswith('PKG_CONFIG') and key.startswith('PKG_') and self.cmake_cache[key]]
for pkg in selected_packages:
self.assertIn(pkg, installed_packages)
def test_has_style(self):
self.assertTrue(self.lmp.has_style('pair_style', 'lj/cut'))
if __name__ == "__main__":
unittest.main()