1
- # test_utils .py
1
+ # test_util .py
2
2
# Copyright (C) 2008, 2009 Michael Trier ([email protected] ) and contributors
3
3
#
4
4
# This module is part of GitPython and is released under
@@ -275,14 +275,14 @@ def test_lock_file(self):
275
275
my_file = tempfile .mktemp ()
276
276
lock_file = LockFile (my_file )
277
277
assert not lock_file ._has_lock ()
278
- # release lock we don't have - fine
278
+ # Release lock we don't have - fine.
279
279
lock_file ._release_lock ()
280
280
281
- # get lock
281
+ # Get lock.
282
282
lock_file ._obtain_lock_or_raise ()
283
283
assert lock_file ._has_lock ()
284
284
285
- # concurrent access
285
+ # Concurrent access.
286
286
other_lock_file = LockFile (my_file )
287
287
assert not other_lock_file ._has_lock ()
288
288
self .assertRaises (IOError , other_lock_file ._obtain_lock_or_raise )
@@ -293,7 +293,7 @@ def test_lock_file(self):
293
293
other_lock_file ._obtain_lock_or_raise ()
294
294
self .assertRaises (IOError , lock_file ._obtain_lock_or_raise )
295
295
296
- # auto -release on destruction
296
+ # Auto -release on destruction.
297
297
del other_lock_file
298
298
lock_file ._obtain_lock_or_raise ()
299
299
lock_file ._release_lock ()
@@ -303,7 +303,7 @@ def test_blocking_lock_file(self):
303
303
lock_file = BlockingLockFile (my_file )
304
304
lock_file ._obtain_lock ()
305
305
306
- # next one waits for the lock
306
+ # Next one waits for the lock.
307
307
start = time .time ()
308
308
wait_time = 0.1
309
309
wait_lock = BlockingLockFile (my_file , 0.05 , wait_time )
@@ -318,23 +318,23 @@ def test_user_id(self):
318
318
self .assertIn ("@" , get_user_id ())
319
319
320
320
def test_parse_date (self ):
321
- # parse_date(from_timestamp()) must return the tuple unchanged
321
+ # parse_date(from_timestamp()) must return the tuple unchanged.
322
322
for timestamp , offset in (
323
323
(1522827734 , - 7200 ),
324
324
(1522827734 , 0 ),
325
325
(1522827734 , + 3600 ),
326
326
):
327
327
self .assertEqual (parse_date (from_timestamp (timestamp , offset )), (timestamp , offset ))
328
328
329
- # test all supported formats
329
+ # Test all supported formats.
330
330
def assert_rval (rval , veri_time , offset = 0 ):
331
331
self .assertEqual (len (rval ), 2 )
332
332
self .assertIsInstance (rval [0 ], int )
333
333
self .assertIsInstance (rval [1 ], int )
334
334
self .assertEqual (rval [0 ], veri_time )
335
335
self .assertEqual (rval [1 ], offset )
336
336
337
- # now that we are here, test our conversion functions as well
337
+ # Now that we are here, test our conversion functions as well.
338
338
utctz = altz_to_utctz_str (offset )
339
339
self .assertIsInstance (utctz , str )
340
340
self .assertEqual (utctz_to_altz (verify_utctz (utctz )), offset )
@@ -347,13 +347,13 @@ def assert_rval(rval, veri_time, offset=0):
347
347
iso3 = ("2005.04.07 22:13:11 -0000" , 0 )
348
348
alt = ("04/07/2005 22:13:11" , 0 )
349
349
alt2 = ("07.04.2005 22:13:11" , 0 )
350
- veri_time_utc = 1112911991 # the time this represents, in time since epoch, UTC
350
+ veri_time_utc = 1112911991 # The time this represents, in time since epoch, UTC.
351
351
for date , offset in (rfc , iso , iso2 , iso3 , alt , alt2 ):
352
352
assert_rval (parse_date (date ), veri_time_utc , offset )
353
353
# END for each date type
354
354
355
- # and failure
356
- self .assertRaises (ValueError , parse_date , datetime .now ()) # non -aware datetime
355
+ # ... and failure.
356
+ self .assertRaises (ValueError , parse_date , datetime .now ()) # Non -aware datetime.
357
357
self .assertRaises (ValueError , parse_date , "invalid format" )
358
358
self .assertRaises (ValueError , parse_date , "123456789 -02000" )
359
359
self .assertRaises (ValueError , parse_date , " 123456789 -0200" )
@@ -362,7 +362,7 @@ def test_actor(self):
362
362
for cr in (None , self .rorepo .config_reader ()):
363
363
self .assertIsInstance (Actor .committer (cr ), Actor )
364
364
self .assertIsInstance (Actor .author (cr ), Actor )
365
- # END assure config reader is handled
365
+ # END ensure config reader is handled
366
366
367
367
@with_rw_repo ("HEAD" )
368
368
@mock .patch ("getpass.getuser" )
@@ -402,7 +402,7 @@ def test_actor_get_uid_laziness_called(self, mock_get_uid):
402
402
mock_get_uid .return_value = "user"
403
403
committer = Actor .committer (None )
404
404
author = Actor .author (None )
405
- # We can't test with `self.rorepo.config_reader()` here, as the uuid laziness
405
+ # We can't test with `self.rorepo.config_reader()` here, as the UUID laziness
406
406
# depends on whether the user running the test has their global user.name config set.
407
407
self .assertEqual (committer .name , "user" )
408
408
self .assertTrue (committer .email .startswith ("user@" ))
@@ -436,30 +436,30 @@ def test_iterable_list(self, case):
436
436
437
437
self .assertEqual (len (ilist ), 2 )
438
438
439
- # contains works with name and identity
439
+ # Contains works with name and identity.
440
440
self .assertIn (name1 , ilist )
441
441
self .assertIn (name2 , ilist )
442
442
self .assertIn (m2 , ilist )
443
443
self .assertIn (m2 , ilist )
444
444
self .assertNotIn ("invalid" , ilist )
445
445
446
- # with string index
446
+ # With string index.
447
447
self .assertIs (ilist [name1 ], m1 )
448
448
self .assertIs (ilist [name2 ], m2 )
449
449
450
- # with int index
450
+ # With int index.
451
451
self .assertIs (ilist [0 ], m1 )
452
452
self .assertIs (ilist [1 ], m2 )
453
453
454
- # with getattr
454
+ # With getattr.
455
455
self .assertIs (ilist .one , m1 )
456
456
self .assertIs (ilist .two , m2 )
457
457
458
- # test exceptions
458
+ # Test exceptions.
459
459
self .assertRaises (AttributeError , getattr , ilist , "something" )
460
460
self .assertRaises (IndexError , ilist .__getitem__ , "something" )
461
461
462
- # delete by name and index
462
+ # Delete by name and index.
463
463
self .assertRaises (IndexError , ilist .__delitem__ , "something" )
464
464
del ilist [name2 ]
465
465
self .assertEqual (len (ilist ), 1 )
@@ -494,21 +494,21 @@ def test_altz_to_utctz_str(self):
494
494
self .assertEqual (altz_to_utctz_str (- 59 ), "+0000" )
495
495
496
496
def test_from_timestamp (self ):
497
- # Correct offset: UTC+2, should return datetime + tzoffset(+2)
497
+ # Correct offset: UTC+2, should return datetime + tzoffset(+2).
498
498
altz = utctz_to_altz ("+0200" )
499
499
self .assertEqual (
500
500
datetime .fromtimestamp (1522827734 , tzoffset (altz )),
501
501
from_timestamp (1522827734 , altz ),
502
502
)
503
503
504
- # Wrong offset: UTC+58, should return datetime + tzoffset(UTC)
504
+ # Wrong offset: UTC+58, should return datetime + tzoffset(UTC).
505
505
altz = utctz_to_altz ("+5800" )
506
506
self .assertEqual (
507
507
datetime .fromtimestamp (1522827734 , tzoffset (0 )),
508
508
from_timestamp (1522827734 , altz ),
509
509
)
510
510
511
- # Wrong offset: UTC-9000, should return datetime + tzoffset(UTC)
511
+ # Wrong offset: UTC-9000, should return datetime + tzoffset(UTC).
512
512
altz = utctz_to_altz ("-9000" )
513
513
self .assertEqual (
514
514
datetime .fromtimestamp (1522827734 , tzoffset (0 )),
@@ -538,7 +538,7 @@ def test_remove_password_from_command_line(self):
538
538
redacted_cmd_1 = remove_password_if_present (cmd_1 )
539
539
assert username not in " " .join (redacted_cmd_1 )
540
540
assert password not in " " .join (redacted_cmd_1 )
541
- # Check that we use a copy
541
+ # Check that we use a copy.
542
542
assert cmd_1 is not redacted_cmd_1
543
543
assert username in " " .join (cmd_1 )
544
544
assert password in " " .join (cmd_1 )
0 commit comments