Example #1
0
def test_high_precision_stat_time():
    def f():
        st = os.stat('.')
        # should be supported on all platforms, but give a result whose
        # precision might be lower than full nanosecond
        highprec = rposix_stat.get_stat_ns_as_bigint(st, "ctime")
        return '%s;%s' % (st.st_ctime, highprec.str())

    fc = compile(f, [])
    as_string = fc()
    asfloat, highprec = as_string.split(';')
    asfloat = float(asfloat)
    highprec = int(highprec)
    st = os.stat('.')
    assert abs(asfloat - st.st_ctime) < 500e-9
    assert abs(highprec - int(st.st_ctime * 1e9)) < 500
    assert abs(
        rposix_stat.get_stat_ns_as_bigint(st, "ctime").tolong() -
        st.st_ctime * 1e9) < 3
    if rposix_stat.TIMESPEC is not None:
        with lltype.scoped_alloc(rposix_stat.STAT_STRUCT.TO) as stresult:
            rposix_stat.c_stat(".", stresult)
            if sys.platform == "darwin":
                assert 0 <= stresult.c_st_ctimespec.c_tv_nsec <= 999999999
                assert highprec == (
                    int(stresult.c_st_ctimespec.c_tv_sec) * 1000000000 +
                    int(stresult.c_st_ctimespec.c_tv_nsec))
            else:
                assert 0 <= stresult.c_st_ctim.c_tv_nsec <= 999999999
                assert highprec == (
                    int(stresult.c_st_ctim.c_tv_sec) * 1000000000 +
                    int(stresult.c_st_ctim.c_tv_nsec))
Example #2
0
def test_high_precision_stat_time():
    def f():
        st = os.stat('.')
        # should be supported on all platforms, but give a result whose
        # precision might be lower than full nanosecond
        highprec = rposix_stat.get_stat_ns_as_bigint(st, "ctime")
        return '%s;%s' % (st.st_ctime, highprec.str())
    fc = compile(f, [])
    as_string = fc()
    asfloat, highprec = as_string.split(';')
    asfloat = float(asfloat)
    highprec = int(highprec)
    st = os.stat('.')
    assert abs(asfloat - st.st_ctime) < 500e-9
    assert abs(highprec - int(st.st_ctime * 1e9)) < 500
    assert abs(rposix_stat.get_stat_ns_as_bigint(st, "ctime").tolong()
               - st.st_ctime * 1e9) < 3
    if rposix_stat.TIMESPEC is not None:
        with lltype.scoped_alloc(rposix_stat.STAT_STRUCT.TO) as stresult:
            rposix_stat.c_stat(".", stresult)
            assert 0 <= stresult.c_st_ctim.c_tv_nsec <= 999999999
            assert highprec == (int(stresult.c_st_ctim.c_tv_sec) * 1000000000
                                + int(stresult.c_st_ctim.c_tv_nsec))
Example #3
0
 def f():
     st = os.stat('.')
     # should be supported on all platforms, but give a result whose
     # precision might be lower than full nanosecond
     highprec = rposix_stat.get_stat_ns_as_bigint(st, "ctime")
     return '%s;%s' % (st.st_ctime, highprec.str())
Example #4
0
 def f():
     st = os.stat('.')
     # should be supported on all platforms, but give a result whose
     # precision might be lower than full nanosecond
     highprec = rposix_stat.get_stat_ns_as_bigint(st, "ctime")
     return '%s;%s' % (st.st_ctime, highprec.str())