Extract reusable device protocols, ports and logic analyzers from SETGUI
This commit is contained in:
38
python/tests/test_shared_library_boundary.py
Normal file
38
python/tests/test_shared_library_boundary.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Shared libraries must import without the desktop application or Qt."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
class LibraryBoundaryTests(unittest.TestCase):
|
||||
def test_cores_import_with_gui_and_qt_blocked(self):
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
code = '''
|
||||
import importlib, importlib.abc, pkgutil, sys
|
||||
class BlockGui(importlib.abc.MetaPathFinder):
|
||||
def find_spec(self, fullname, path=None, target=None):
|
||||
if fullname.split('.')[0] in ('gui_desktop', 'PySide6', 'PySide2'):
|
||||
raise ImportError('Application dependency in shared core: ' + fullname)
|
||||
sys.meta_path.insert(0, BlockGui())
|
||||
for name in ('logic_analyzer', 'set_devices'):
|
||||
package = importlib.import_module(name)
|
||||
for module in pkgutil.walk_packages(package.__path__, name + '.'):
|
||||
if '.qt_ports' not in module.name:
|
||||
importlib.import_module(module.name)
|
||||
assert 'gui_desktop' not in sys.modules
|
||||
'''
|
||||
env = dict(os.environ, PYTHONPATH=str(root))
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
result = subprocess.run([sys.executable, '-c', code], cwd=directory, env=env,
|
||||
capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_no_reverse_imports_in_sources(self):
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
for name in ('logic_analyzer', 'set_devices', 'altera_logic'):
|
||||
for path in (root / name).rglob('*.py'):
|
||||
text = path.read_text(encoding='utf-8')
|
||||
self.assertNotIn('gui_desktop', text, str(path))
|
||||
Reference in New Issue
Block a user