From 3224a441733f02a1c0a910efb60c434056cc5b68 Mon Sep 17 00:00:00 2001 From: SET Date: Thu, 13 Aug 2020 16:59:12 -0300 Subject: [PATCH] Added test for decimal point locale support. Hopefully works on docker ... --- kiplot/__main__.py | 17 ++++++++++++++++- tests/board_samples/RLC_sort.sch | 2 +- tests/test_plot/test_int_bom.py | 2 +- tests/utils/context.py | 24 +++++++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/kiplot/__main__.py b/kiplot/__main__.py index 94d9b12d..83c4c8cd 100644 --- a/kiplot/__main__.py +++ b/kiplot/__main__.py @@ -163,8 +163,23 @@ def solve_board_file(schematic, a_board_file): return board_file +def set_locale(): + """ Try to se the locale for all the cataegories. + If it fails try for LC_NUMERIC (the one we need for tests). """ + try: + locale.setlocale(locale.LC_ALL, '') + return + except locale.Error: + pass + try: + locale.setlocale(locale.LC_NUMERIC, '') + return + except locale.Error: + pass + + def main(): - locale.setlocale(locale.LC_ALL, '') + set_locale() ver = 'KiPlot '+__version__+' - '+__copyright__+' - License: '+__license__ args = docopt(__doc__, version=ver, options_first=True) diff --git a/tests/board_samples/RLC_sort.sch b/tests/board_samples/RLC_sort.sch index f08c18ea..b8749356 100644 --- a/tests/board_samples/RLC_sort.sch +++ b/tests/board_samples/RLC_sort.sch @@ -29,7 +29,7 @@ L Device:R R2 U 1 1 5E6A330D P 2500 2550 F 0 "R2" V 2580 2550 50 0000 C CNN -F 1 "8.2k" V 2500 2550 50 0000 C CNN +F 1 "8,2k" V 2500 2550 50 0000 C CNN F 2 "Resistor_SMD:R_0805_2012Metric" V 2430 2550 50 0001 C CNN F 3 "~" H 2500 2550 50 0001 C CNN 1 2500 2550 diff --git a/tests/test_plot/test_int_bom.py b/tests/test_plot/test_int_bom.py index 73c1e2b0..8d052b48 100644 --- a/tests/test_plot/test_int_bom.py +++ b/tests/test_plot/test_int_bom.py @@ -345,7 +345,7 @@ def test_int_bom_sort_1(): prj = 'RLC_sort' ext = 'csv' ctx = context.TestContextSCH('test_int_bom_sort_1', prj, 'int_bom_simple_csv', BOM_DIR) - ctx.run() + ctx.run(do_locale=True) out = prj + '-bom.' + ext rows, header = ctx.load_csv(out) ref_column = header.index(REF_COLUMN_NAME) diff --git a/tests/utils/context.py b/tests/utils/context.py index 93ad6c84..2208e73b 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -154,7 +154,7 @@ class TestContext(object): f.write('Dummy file\n') def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None, no_out_dir=False, no_board_file=False, - no_yaml_file=False, chdir_out=False, no_verbose=False, extra_debug=False): + no_yaml_file=False, chdir_out=False, no_verbose=False, extra_debug=False, do_locale=False): logging.debug('Running '+self.test_name) # Change the command to be local and add the board and output arguments cmd = [COVERAGE_SCRIPT, 'run', '-a'] @@ -178,6 +178,18 @@ class TestContext(object): cmd = cmd+['-d', self.output_dir] if extra is not None: cmd = cmd+extra + # Do we need a custom locale? + old_LOCPATH = None + old_LANG = None + if do_locale: + # Setup an Spanish for Argentina using UTF-8 locale + old_LOCPATH = os.environ.get('LOCPATH') + old_LANG = os.environ.get('LANG') + os.environ['LOCPATH'] = os.path.abspath('tests/data') + os.environ['LANG'] = 'es_AR.UTF-8' + #os.environ['LANG'] = 'en_US.UTF-8' + logging.debug('LOCPATH='+os.environ['LOCPATH']) + logging.debug('LANG='+os.environ['LANG']) logging.debug(cmd) out_filename = self.get_out_path('output.txt') err_filename = self.get_out_path('error.txt') @@ -224,6 +236,16 @@ class TestContext(object): self.err = os.read(f_err, 1000000) os.close(f_err) self.err = self.err.decode() + # Do we need to restore the locale? + if do_locale: + if old_LOCPATH: + os.environ['LOCPATH'] = old_LOCPATH + else: + del os.environ['LOCPATH'] + if old_LANG: + os.environ['LANG'] = old_LANG + else: + del os.environ['LANG'] def search_out(self, text): m = re.search(text, self.out, re.MULTILINE)