1
This commit is contained in:
1 parent
2ea1a79bda
commit
85425483c0
50 files changed
+6468
-1854
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""Run offline tests. Loopback HTTP fixtures are allowed; exchange connections are forbidden."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
|
||||
def offline(event, args):
|
||||
if event == 'socket.connect':
|
||||
host = args[1][0]
|
||||
elif event == 'socket.getaddrinfo':
|
||||
host = args[0]
|
||||
else:
|
||||
return
|
||||
if host not in (None, 'localhost', '::1') and not str(host).startswith('127.'):
|
||||
raise RuntimeError('External network is disabled during tests')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 1:
|
||||
for suite in ('tests', 'meme_matcher/tests'):
|
||||
result = subprocess.run([sys.executable, '-B', __file__, suite], cwd=ROOT)
|
||||
if result.returncode:
|
||||
sys.exit(result.returncode)
|
||||
else:
|
||||
os.chdir(ROOT)
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.addaudithook(offline)
|
||||
suite = unittest.defaultTestLoader.discover(str(ROOT / sys.argv[1]))
|
||||
sys.exit(not unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful())
|
||||
Reference in new issue
Block a user