File: timeTools_test.py

package info (click to toggle)
fonttools 4.61.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,584 kB
  • sloc: python: 145,091; xml: 103; makefile: 24
file content (43 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from fontTools.misc.timeTools import (
    asctime,
    timestampNow,
    timestampToString,
    timestampFromString,
    epoch_diff,
)
import os
import time
import locale
import pytest


def test_asctime():
    assert isinstance(asctime(), str)
    assert asctime(time.gmtime(0)) == "Thu Jan  1 00:00:00 1970"


def test_source_date_epoch():
    os.environ["SOURCE_DATE_EPOCH"] = "150687315"
    assert timestampNow() + epoch_diff == 150687315

    # Check that malformed value fail, any better way?
    os.environ["SOURCE_DATE_EPOCH"] = "ABCDEFGHI"
    with pytest.raises(ValueError):
        timestampNow()

    del os.environ["SOURCE_DATE_EPOCH"]
    assert timestampNow() + epoch_diff != 150687315


# test for issue #1838
def test_date_parsing_with_locale():
    l = locale.getlocale(locale.LC_TIME)
    try:
        locale.setlocale(locale.LC_TIME, "de_DE.utf8")
    except locale.Error:
        pytest.skip("Locale de_DE not available")

    try:
        assert timestampFromString(timestampToString(timestampNow()))
    finally:
        locale.setlocale(locale.LC_TIME, l)