0

I'm doing tests for a system on which the output depends on the current date, the system compares the output with an expected output I prepared previously. For the test to pass, I shall invoke the system with the same date so I can obtain the same results and the test can succeed. otherwise, the test will fail.

I want to set the current date within the cmd scope ONLY without affecting the current date of the system.

This date is accessed either using the latex (\the\year) variable and from python using the datetime library (datetime.now()).

I tried using the date command but this changes the date in the system which triggers many operations and errors (Antivirus updates, etc ...) because its a corporate server so I should not change the date of the server while running the tests.

I can write code to neglect the comparison of the dates, but this operation is too complicated as the date is written in generated PDFs and many other files are in different formats.

So, is it possible to change the current date within the windows 10 command line ONLY (Not system scope)?

Praveen Rewar
  • 952
  • 1
  • 7
  • 18
Mohamed
  • 11
  • 1
  • 4
  • Have you try to [mock](https://docs.python.org/3/library/unittest.mock.html) the date function in python? – ndclt Aug 14 '19 at 08:51
  • It sounds like the application should have a "business_date" setting; a parameter, environment variable, read from a config file, etc... – lit Aug 14 '19 at 13:46
  • @ndclt I read about the mock and during my search i found freezegun library from which a function freeze_time handle fixing the date to a certain date before invoking the system under test – Mohamed Aug 15 '19 at 13:40
  • Nice library. Do your tests run in Python? What precision do you need about the time or date whech checking there are equals? – ndclt Aug 15 '19 at 13:47

2 Answers2

0

you might find your answer here Stackoverflow Discussion about Datetime from CMD and here Getting Datetime independently from Windows locale

Furthermore, you can set a locale in python this way:

import locale
locale.setlocale(locale.LC_TIME, "your/locale/here")
cptnJ
  • 230
  • 2
  • 8
0

making something that works across both Python and LaTeX is awkward and very OS specific. google suggests that tools like RunAsDate exists for Windows but they hook some pretty nasty internal calls to do things

as @ndclt suggested, in Python the standard approach would be to "mock" the relevant functions out such that they return a known value. under LaTeX you could write a "test harness" that does \year=2000 \input{orig.tex}

Sam Mason
  • 15,216
  • 1
  • 41
  • 60