Skip to content

Commit ac567dc

Browse files
bkalashnikovbogdandm
bkalashnikov
authored andcommitted
Fix code generation test
1 parent 0dd95dc commit ac567dc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/test_cli/test_script.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import imp
21
import json
32
import re
43
import subprocess
54
import sys
65
import tempfile
6+
import types
7+
import uuid
78
from pathlib import Path
89
from time import time
9-
from typing import Tuple
1010

1111
import pytest
1212

@@ -95,6 +95,12 @@ def test_help():
9595
]
9696

9797

98+
def load_model(code):
99+
module = types.ModuleType(uuid.uuid4().hex)
100+
exec(code, module.__dict__)
101+
return module
102+
103+
98104
def execute_test(command, output_file: Path = None, output=None) -> str:
99105
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
100106
stdout, stderr = map(bytes.decode, proc.communicate())
@@ -107,11 +113,8 @@ def execute_test(command, output_file: Path = None, output=None) -> str:
107113
assert not stderr, stderr
108114
assert stdout, stdout
109115
assert proc.returncode == 0
110-
# Note: imp package is deprecated but I can't find a way to create dummy module using importlib
111-
module = imp.new_module("test_model")
112-
sys.modules["test_model"] = module
113116
try:
114-
exec(compile(stdout, "test_model.py", "exec"), module.__dict__)
117+
load_model(stdout)
115118
except Exception as e:
116119
assert not e, stdout
117120

0 commit comments

Comments
 (0)