11"""pytest fixtures for this directory.""" 
22
3+ import  datetime 
34import  re 
5+ import  time 
46
57import  pytest 
68
911
1012RE_BANNER  =  re .compile ('>(?:<a href="([^"]+)">)?<b>Warning:</b> This document is for ([^<]+).(?:</a>)?</p>' )
1113RE_URLS  =  re .compile ('<li><a href="[^"]+">[^<]+</a></li>' )
14+ ROOT_TS  =  int (time .mktime ((2016 , 12 , 5 , 3 , 17 , 5 , 0 , 0 , 0 )))
15+ 
16+ 
17+ def  author_committer_dates (offset ):
18+     """Return ISO time for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables. 
19+ 
20+     Always starts on December 05 2016 03:17:05 AM local time. Committer date always 2 seconds after author date. 
21+ 
22+     :param int offset: Minutes to offset both timestamps. 
23+ 
24+     :return: GIT_AUTHOR_DATE and GIT_COMMITTER_DATE timestamps, can be merged into os.environ. 
25+     :rtype: dict 
26+     """ 
27+     dt  =  datetime .datetime .fromtimestamp (ROOT_TS ) +  datetime .timedelta (minutes = offset )
28+     env  =  dict (GIT_AUTHOR_DATE = str (dt ))
29+     dt  +=  datetime .timedelta (seconds = 2 )
30+     env ['GIT_COMMITTER_DATE' ] =  str (dt )
31+     return  env 
1232
1333
1434def  run (directory , command , * args , ** kwargs ):
@@ -32,6 +52,8 @@ def pytest_namespace():
3252    :rtype: dict 
3353    """ 
3454    return  dict (
55+         author_committer_dates = author_committer_dates ,
56+         ROOT_TS = ROOT_TS ,
3557        run = run ,
3658    )
3759
@@ -132,7 +154,7 @@ def fx_local_commit(local_empty):
132154    """ 
133155    local_empty .join ('README' ).write ('Dummy readme file.' )
134156    run (local_empty , ['git' , 'add' , 'README' ])
135-     run (local_empty , ['git' , 'commit' , '-m' , 'Initial commit.' ])
157+     run (local_empty , ['git' , 'commit' , '-m' , 'Initial commit.' ],  environ = author_committer_dates ( 0 ) )
136158    return  local_empty 
137159
138160
@@ -191,12 +213,12 @@ def outdate_local(tmpdir, local_light, remote):
191213    run (local_ahead , ['git' , 'clone' , remote , '.' ])
192214    run (local_ahead , ['git' , 'checkout' , '-b' , 'un_pushed_branch' ])
193215    local_ahead .join ('README' ).write ('changed' )
194-     run (local_ahead , ['git' , 'commit' , '-am' , 'Changed new branch' ])
216+     run (local_ahead , ['git' , 'commit' , '-am' , 'Changed new branch' ],  environ = author_committer_dates ( 1 ) )
195217    run (local_ahead , ['git' , 'tag' , 'nb_tag' ])
196218    run (local_ahead , ['git' , 'checkout' , '--orphan' , 'orphaned_branch' ])
197219    local_ahead .join ('README' ).write ('new' )
198220    run (local_ahead , ['git' , 'add' , 'README' ])
199-     run (local_ahead , ['git' , 'commit' , '-m' , 'Added new README' ])
221+     run (local_ahead , ['git' , 'commit' , '-m' , 'Added new README' ],  environ = author_committer_dates ( 2 ) )
200222    run (local_ahead , ['git' , 'tag' , '--annotate' , '-m' , 'Tag annotation.' , 'ob_at' ])
201223    run (local_ahead , ['git' , 'push' , 'origin' , 'nb_tag' , 'orphaned_branch' , 'ob_at' ])
202224    return  local_ahead 
@@ -248,7 +270,7 @@ def fx_local_docs(local):
248270        'Sub page documentation 3.\n ' 
249271    )
250272    run (local , ['git' , 'add' , 'conf.py' , 'contents.rst' , 'one.rst' , 'two.rst' , 'three.rst' ])
251-     run (local , ['git' , 'commit' , '-m' , 'Adding docs.' ])
273+     run (local , ['git' , 'commit' , '-m' , 'Adding docs.' ],  environ = author_committer_dates ( 3 ) )
252274    run (local , ['git' , 'push' , 'origin' , 'master' ])
253275    return  local 
254276
@@ -263,7 +285,7 @@ def local_docs_ghp(local_docs):
263285    run (local_docs , ['git' , 'rm' , '-rf' , '.' ])
264286    local_docs .join ('README' ).write ('Orphaned branch for HTML docs.' )
265287    run (local_docs , ['git' , 'add' , 'README' ])
266-     run (local_docs , ['git' , 'commit' , '-m' , 'Initial Commit' ])
288+     run (local_docs , ['git' , 'commit' , '-m' , 'Initial Commit' ],  environ = author_committer_dates ( 4 ) )
267289    run (local_docs , ['git' , 'push' , 'origin' , 'gh-pages' ])
268290    run (local_docs , ['git' , 'checkout' , 'master' ])
269291    return  local_docs 
0 commit comments