How do I fix this test so it runs on Windows? (it uses tzset)

C

Chris Withers

Nobody said:
MSVCRT has _tzset(), which understands the TZ environment variable.

http://msdn.microsoft.com/en-us/library/90s5c885(VS.80).aspx

For whatever reason, tython's "time" module doesn't provide the tzset()
function on Windows. However, you should be able to use it via ctypes.

This sounds pretty heavyweight for a unit test.
I'm not even sure how I would do this ;-)

Where can I find an example?

....or better yet, does anyone have any alternative solutions?

Chris
 
N

Nobody

This sounds pretty heavyweight for a unit test.
I'm not even sure how I would do this ;-)

from ctypes import cdll
tzset = cdll.msvcrt._tzset

Except ... Python doesn't appear to use the OS time conversion functions,
so calling _tzset() has no effect.

And the documentation doesn't specify whether modifying time.timezone is
allowed.

IOW, I don't think there's any robust way to ask "what would have happened
if TZ been set to <whatever> at startup", other than running a separate
script with the appropriate TZ setting.

You can perform conversions with an explicit timezone using the "datetime"
module, but that won't help you test the behaviour of code which uses the
"time" module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top