From 6ff6fcc9754a0645138496b26ca45f594eeb7bf2 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sat, 9 Jul 2022 16:26:46 -0300 Subject: [PATCH] [Tests] Better support when KiBot is also installed at user level --- tests/test_plot/force_colorama_error.py | 6 +++++- tests/test_plot/force_pcbnew_error.py | 6 +++++- tests/test_plot/force_xlsx_error.py | 6 +++++- tests/test_plot/force_yaml_error.py | 6 +++++- tests/test_plot/kiconf_init.py | 6 +++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/test_plot/force_colorama_error.py b/tests/test_plot/force_colorama_error.py index 66a8962b..28c2cc88 100755 --- a/tests/test_plot/force_colorama_error.py +++ b/tests/test_plot/force_colorama_error.py @@ -3,7 +3,11 @@ import os import sys # Setup the path to load local kibot module prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -if prev_dir not in sys.path: +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) # Force the pcbnew module load to fail sys.modules['colorama'] = None diff --git a/tests/test_plot/force_pcbnew_error.py b/tests/test_plot/force_pcbnew_error.py index cf7f5e18..6692e7b2 100755 --- a/tests/test_plot/force_pcbnew_error.py +++ b/tests/test_plot/force_pcbnew_error.py @@ -4,7 +4,11 @@ import sys # Setup the path to load local kibot module cur_dir = os.path.dirname(os.path.abspath(__file__)) prev_dir = os.path.dirname(os.path.dirname(cur_dir)) -if prev_dir not in sys.path: +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) if len(sys.argv) > 1 and sys.argv[1] == 'fake': fake_dir = os.path.join(cur_dir, 'fake_pcbnew') diff --git a/tests/test_plot/force_xlsx_error.py b/tests/test_plot/force_xlsx_error.py index 09587160..75be6354 100755 --- a/tests/test_plot/force_xlsx_error.py +++ b/tests/test_plot/force_xlsx_error.py @@ -3,7 +3,11 @@ import os import sys # Setup the path to load local kibot module prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -if prev_dir not in sys.path: +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) # Force the xlsxwriter module load to fail sys.modules['xlsxwriter'] = None diff --git a/tests/test_plot/force_yaml_error.py b/tests/test_plot/force_yaml_error.py index a6a88fd6..6530ba89 100755 --- a/tests/test_plot/force_yaml_error.py +++ b/tests/test_plot/force_yaml_error.py @@ -3,7 +3,11 @@ import os import sys # Setup the path to load local kibot module prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -if prev_dir not in sys.path: +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) # Force the pcbnew module load to fail sys.modules['yaml'] = None diff --git a/tests/test_plot/kiconf_init.py b/tests/test_plot/kiconf_init.py index 814b51b3..2eeb7f97 100755 --- a/tests/test_plot/kiconf_init.py +++ b/tests/test_plot/kiconf_init.py @@ -14,7 +14,11 @@ if prev_dir not in sys.path: sys.path.insert(0, prev_dir) # One more level for the project prev_dir = os.path.dirname(prev_dir) -if prev_dir not in sys.path: +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) import kibot.log as log