def test_json_serialization(): # on windows, we can't open a file twice, so save the name and unlink # manually... try: name = None with tempfile.NamedTemporaryFile(delete=False) as temp: name = temp.name json_dump(fontManager, name) copy = json_load(name) finally: if name and os.path.exists(name): os.remove(name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({ 'family': 'STIXGeneral' }, { 'family': 'Bitstream Vera Sans', 'weight': 700 }, { 'family': 'no such font family' }): fp = FontProperties(**prop) assert (fontManager.findfont( fp, rebuild_if_missing=False) == copy.findfont( fp, rebuild_if_missing=False))
def test_json_serialization(): with tempfile.NamedTemporaryFile() as temp: json_dump(fontManager, temp.name) copy = json_load(temp.name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert_equal(fontManager.findfont(fp, rebuild_if_missing=False), copy.findfont(fp, rebuild_if_missing=False))
def test_json_serialization(tmpdir): # Can't open a NamedTemporaryFile twice on Windows, so use a temporary # directory instead. path = Path(tmpdir, "fontlist.json") json_dump(fontManager, path) copy = json_load(path) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert (fontManager.findfont(fp, rebuild_if_missing=False) == copy.findfont(fp, rebuild_if_missing=False))
def test_json_serialization(): with tempfile.NamedTemporaryFile() as temp: json_dump(fontManager, temp.name) copy = json_load(temp.name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({ 'family': 'STIXGeneral' }, { 'family': 'Bitstream Vera Sans', 'weight': 700 }, { 'family': 'no such font family' }): fp = FontProperties(**prop) assert_equal(fontManager.findfont(fp, rebuild_if_missing=False), copy.findfont(fp, rebuild_if_missing=False))
def test_json_serialization(): # on windows, we can't open a file twice, so save the name and unlink # manually... try: name = None with tempfile.NamedTemporaryFile(delete=False) as temp: name = temp.name json_dump(fontManager, name) copy = json_load(name) finally: if name and os.path.exists(name): os.remove(name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert (fontManager.findfont(fp, rebuild_if_missing=False) == copy.findfont(fp, rebuild_if_missing=False))