test_examples.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import os
  2. import sys
  3. from pathlib import Path
  4. import importlib.util
  5. import pytest
  6. import tempfile
  7. import shutil
  8. import openfhe as fhe
  9. pytestmark = pytest.mark.skipif(fhe.get_native_int() == 32, reason="Doesn't work for NATIVE_INT=32")
  10. EXAMPLES_SCRIPTS_PATH = os.path.join(Path(__file__).parent.parent, "examples", "pke")
  11. def importhelper(path, modulename):
  12. spec = importlib.util.spec_from_file_location(
  13. modulename, os.path.join(path, modulename + ".py")
  14. )
  15. module = importlib.util.module_from_spec(spec)
  16. sys.modules[modulename] = module
  17. spec.loader.exec_module(module)
  18. return module
  19. @pytest.mark.parametrize(
  20. "raw_modulename",
  21. [
  22. "simple-ckks-bootstrapping.py",
  23. "simple-integers-serial-bgvrns.py",
  24. "function-evaluation.py",
  25. "advanced-real-numbers-128.py",
  26. "simple-integers-bgvrns.py",
  27. "simple-integers-serial.py",
  28. "polynomial-evaluation.py",
  29. "scheme-switching.py",
  30. "tckks-interactive-mp-bootstrapping.py",
  31. "advanced-real-numbers.py",
  32. "threshold-fhe-5p.py",
  33. "simple-integers.py",
  34. "simple-real-numbers-serial.py",
  35. "iterative-ckks-bootstrapping.py",
  36. "tckks-interactive-mp-bootstrapping-Chebyschev.py",
  37. "simple-real-numbers.py",
  38. "threshold-fhe.py",
  39. "pre-buffer.py",
  40. ],
  41. )
  42. def test_run_scripts(raw_modulename):
  43. with tempfile.TemporaryDirectory() as td:
  44. os.mkdir(td + "/demoData")
  45. modulename_py = raw_modulename.replace("-", "_")
  46. shutil.copyfile(
  47. os.path.join(EXAMPLES_SCRIPTS_PATH, raw_modulename),
  48. os.path.join(td, modulename_py),
  49. )
  50. sys.path.insert(0, td)
  51. modulename = modulename_py.split(".")[0]
  52. print(f"-*- running module {modulename} -*-")
  53. module = importhelper(td, modulename)
  54. module.main()