From ef6f60510ac13edb69e3c2f6bd23c03532a64124 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Mon, 7 Apr 2025 09:50:22 +0200 Subject: [PATCH] Test: fix MaterialTestCases failing on unicode character output --- src/Mod/Material/materialtests/TestMaterials.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Mod/Material/materialtests/TestMaterials.py b/src/Mod/Material/materialtests/TestMaterials.py index 66f6db0ed7..fb72bce1e6 100644 --- a/src/Mod/Material/materialtests/TestMaterials.py +++ b/src/Mod/Material/materialtests/TestMaterials.py @@ -27,6 +27,7 @@ Test module for FreeCAD material cards and APIs import unittest import FreeCAD import Materials +import sys parseQuantity = FreeCAD.Units.parseQuantity @@ -37,6 +38,15 @@ class MaterialTestCases(unittest.TestCase): def setUp(self): """ Setup function to initialize test data """ + # The test for ThermalExpansionCoefficient causes problems with some localizations + # due to the Unicode mu ('\u03bc') character in the units. This will happen with + # locales that don't support UTF8 such as zh_CN (It does support UTF-8) + try: + sys.stdout.reconfigure(errors='replace') + except: + # reconfigure appeared in 3.7, hope for the best... + pass + self.ModelManager = Materials.ModelManager() self.MaterialManager = Materials.MaterialManager() self.uuids = Materials.UUIDs() @@ -145,12 +155,6 @@ class MaterialTestCases(unittest.TestCase): self.assertIn("SpecularColor", properties) self.assertIn("Transparency", properties) - # - # The test for ThermalExpansionCoefficient causes problems with some localizations - # due to the Unicode mu character in the units. This will happen with - # locales that don't support UTF8 such as zh_CN (It does support UTF-8) - # - # When this is a problem simply comment the lines printing ThermalExpansionCoefficient print("Density " + properties["Density"]) # print("BulkModulus " + properties["BulkModulus"]) print("PoissonRatio " + properties["PoissonRatio"])