Skip to content

Commit 0475a3d

Browse files
committed
[Tests][Fixed] Isolated GUI and KiBoM tests
They seem to have some LANG interference
1 parent f2e704d commit 0475a3d

2 files changed

Lines changed: 36 additions & 32 deletions

File tree

tests/test_plot/test_gui.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def save_events(self, cfg):
237237
writer.writerows(self.e)
238238

239239

240-
def run_test(num, test_dir, project, recipe, keep_project=False, no_board_file=False, no_yaml_file=False):
240+
def run_test(num, monkeypatch, test_dir, project, recipe, keep_project=False, no_board_file=False, no_yaml_file=False):
241241
id = "%04d" % num
242242
base_name = sys._getframe(1).f_code.co_name[9:]
243243
yaml_base = f'{id}.kibot.yaml'
@@ -251,21 +251,21 @@ def run_test(num, test_dir, project, recipe, keep_project=False, no_board_file=F
251251
recipe(ctx).save_events(cfg)
252252
logging.debug(f'Using `{cfg}` events')
253253
yaml_out = ctx.get_out_path('result.kibot.yaml')
254-
old_lang = os.environ.get('LANG')
255-
try:
256-
os.environ['LANG'] = 'en'
257-
with Xvfb(width=1920, height=1080, colordepth=24):
258-
with start_record(True, ctx.output_dir, base_name):
259-
extra = ['--gui', '-I', cfg]
260-
ctx.run(extra=extra, no_board_file=no_board_file, no_yaml_file=no_yaml_file)
261-
finally:
262-
with open(yaml_ori) as f:
263-
yaml_res = f.read()
264-
with open(yaml_ori, 'w') as f:
265-
f.write(yaml_txt)
266-
with open(yaml_out, 'w') as f:
267-
f.write(yaml_res)
268-
os.environ['LANG'] = old_lang
254+
with monkeypatch.context() as m:
255+
m.setenv("LANG", "en")
256+
try:
257+
os.environ['LANG'] = 'en'
258+
with Xvfb(width=1920, height=1080, colordepth=24):
259+
with start_record(True, ctx.output_dir, base_name):
260+
extra = ['--gui', '-I', cfg]
261+
ctx.run(extra=extra, no_board_file=no_board_file, no_yaml_file=no_yaml_file)
262+
finally:
263+
with open(yaml_ori) as f:
264+
yaml_res = f.read()
265+
with open(yaml_ori, 'w') as f:
266+
f.write(yaml_txt)
267+
with open(yaml_out, 'w') as f:
268+
f.write(yaml_res)
269269
ctx.compare_txt(text=os.path.abspath(yaml_out), reference=os.path.abspath('tests/GUI/cfg_out/'+yaml_base))
270270
ctx.clean_up(keep_project=keep_project)
271271

@@ -340,17 +340,18 @@ def try_groups_1_recipe(ctx):
340340

341341

342342
@pytest.mark.indep
343-
def test_gui_new_board_view_1(test_dir):
343+
def test_gui_new_board_view_1(test_dir, monkeypatch):
344344
""" We start without config.
345345
Force a known YAML, set an SCH, add a boardview output, name it test_output and save """
346-
run_test(1, test_dir, 'light_control', new_board_view_recipe, keep_project=True, no_board_file=True, no_yaml_file=True)
346+
run_test(1, monkeypatch, test_dir, 'light_control', new_board_view_recipe, keep_project=True, no_board_file=True,
347+
no_yaml_file=True)
347348

348349

349350
@pytest.mark.indep
350-
def test_gui_new_board_view_2(test_dir):
351+
def test_gui_new_board_view_2(test_dir, monkeypatch):
351352
""" We start with config and SCH.
352353
Add a boardview output, name it test_output and save """
353-
run_test(2, test_dir, 'light_control', new_board_view_deep_recipe, keep_project=True)
354+
run_test(2, monkeypatch, test_dir, 'light_control', new_board_view_deep_recipe, keep_project=True)
354355

355356

356357
def get_simple(path, items):
@@ -503,25 +504,25 @@ def try_all_variants_recipe(ctx):
503504

504505

505506
@pytest.mark.indep
506-
def test_gui_try_all_outputs_1(test_dir):
507-
run_test(3, test_dir, 'light_control', try_all_outputs_recipe, keep_project=True)
507+
def test_gui_try_all_outputs_1(test_dir, monkeypatch):
508+
run_test(3, monkeypatch, test_dir, 'light_control', try_all_outputs_recipe, keep_project=True)
508509

509510

510511
@pytest.mark.indep
511-
def test_gui_try_all_preflights_1(test_dir):
512-
run_test(4, test_dir, 'light_control', try_all_preflights_recipe, keep_project=True)
512+
def test_gui_try_all_preflights_1(test_dir, monkeypatch):
513+
run_test(4, monkeypatch, test_dir, 'light_control', try_all_preflights_recipe, keep_project=True)
513514

514515

515516
@pytest.mark.indep
516-
def test_gui_try_all_filters_1(test_dir):
517-
run_test(5, test_dir, 'light_control', try_all_filters_recipe, keep_project=True)
517+
def test_gui_try_all_filters_1(test_dir, monkeypatch):
518+
run_test(5, monkeypatch, test_dir, 'light_control', try_all_filters_recipe, keep_project=True)
518519

519520

520521
@pytest.mark.indep
521-
def test_gui_try_all_variants_1(test_dir):
522-
run_test(6, test_dir, 'light_control', try_all_variants_recipe, keep_project=True)
522+
def test_gui_try_all_variants_1(test_dir, monkeypatch):
523+
run_test(6, monkeypatch, test_dir, 'light_control', try_all_variants_recipe, keep_project=True)
523524

524525

525526
@pytest.mark.indep
526-
def test_gui_groups_1(test_dir):
527-
run_test(7, test_dir, 'light_control', try_groups_1_recipe, keep_project=True)
527+
def test_gui_groups_1(test_dir, monkeypatch):
528+
run_test(7, monkeypatch, test_dir, 'light_control', try_groups_1_recipe, keep_project=True)

tests/test_plot/test_yaml_errors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,12 @@ def test_error_bom_wrong_format(test_dir):
450450

451451

452452
@pytest.mark.indep
453-
def test_error_bom_column(test_dir):
453+
def test_error_bom_column(test_dir, monkeypatch):
454454
ctx = context.TestContext(test_dir, PRJ, 'error_bom_column')
455-
ctx.run(EXIT_BAD_CONFIG, no_board_file=True, extra=['-e', os.path.join(ctx.get_board_dir(), 'bom'+context.KICAD_SCH_EXT)])
455+
with monkeypatch.context() as m:
456+
m.setenv("LANG", "")
457+
ctx.run(EXIT_BAD_CONFIG, no_board_file=True, extra=['-e', os.path.join(ctx.get_board_dir(),
458+
'bom'+context.KICAD_SCH_EXT)])
456459
assert ctx.search_err("Invalid column name .?Impossible.?")
457460
ctx.clean_up(keep_project=True)
458461

0 commit comments

Comments
 (0)