1from fontTools.misc.timeTools import asctime, timestampNow, timestampToString, timestampFromString, epoch_diff 2import os 3import time 4import locale 5import pytest 6 7 8def test_asctime(): 9 assert isinstance(asctime(), str) 10 assert asctime(time.gmtime(0)) == 'Thu Jan 1 00:00:00 1970' 11 12 13def test_source_date_epoch(): 14 os.environ["SOURCE_DATE_EPOCH"] = "150687315" 15 assert timestampNow() + epoch_diff == 150687315 16 17 # Check that malformed value fail, any better way? 18 os.environ["SOURCE_DATE_EPOCH"] = "ABCDEFGHI" 19 with pytest.raises(ValueError): 20 timestampNow() 21 22 del os.environ["SOURCE_DATE_EPOCH"] 23 assert timestampNow() + epoch_diff != 150687315 24 25 26# test for issue #1838 27def test_date_parsing_with_locale(): 28 l = locale.getlocale(locale.LC_TIME) 29 try: 30 locale.setlocale(locale.LC_TIME, 'de_DE.utf8') 31 except locale.Error: 32 pytest.skip("Locale de_DE not available") 33 34 try: 35 assert timestampFromString(timestampToString(timestampNow())) 36 finally: 37 locale.setlocale(locale.LC_TIME, l) 38