Repository: google/mobly

Issue:
DeprecationWarning for not using raw strings
The Windows test run gave some deprecation warnings:

============================== warnings summary ===============================
mobly\logger.py:32
  T:\src\github\mobly\mobly\logger.py:32: DeprecationWarning: invalid escape sequence \d
    logline_timestamp_re = re.compile('\d\d-\d\d \d\d:\d\d:\d\d.\d\d\d')

tests\mobly\base_test_test.py:152
  T:\src\github\mobly\tests\mobly\base_test_test.py:152: DeprecationWarning: invalid escape sequence \*
    'naming convention test_\*, abort.')

tests\mobly\base_test_test.py:190
  T:\src\github\mobly\tests\mobly\base_test_test.py:190: DeprecationWarning: invalid escape sequence \*
    'naming convention test_\*, abort.')

tests\mobly\test_runner_test.py:262
  T:\src\github\mobly\tests\mobly\test_runner_test.py:262: DeprecationWarning: invalid escape sequence \.
    'TestRunner\._teardown_logger\(\) called before '

tests\mobly\test_runner_test.py:263
  T:\src\github\mobly\tests\mobly\test_runner_test.py:263: DeprecationWarning: invalid escape sequence \.
    'TestRunner\.setup_logger\(\)!'):

tests\mobly\controllers\android_device_test.py:191
  T:\src\github\mobly\tests\mobly\controllers\android_device_test.py:191: DeprecationWarning: invalid escape sequence \[
    expected_msg = "More than one device matched: \['0', '0'\]"

tests\mobly\controllers\android_device_lib\adb_test.py:317
  T:\src\github\mobly\tests\mobly\controllers\android_device_lib\adb_test.py:317: DeprecationWarning: invalid escape sequence \/
    'shell', ['a b', '"blah"', '\/\/'], shell=False)

tests\mobly\controllers\android_device_lib\adb_test.py:318
  T:\src\github\mobly\tests\mobly\controllers\android_device_lib\adb_test.py:318: DeprecationWarning: invalid escape sequence \/
    self.assertEqual(adb_cmd, ['adb', 'shell', 'a b', '"blah"', "\/\/"])

tests\mobly\controllers\android_device_lib\adb_test.py:358
  T:\src\github\mobly\tests\mobly\controllers\android_device_lib\adb_test.py:358: DeprecationWarning: invalid escape sequence \/
    'shell', ['a b', '"blah"', '\/\/'], shell=True)


Discussion:

Resolving patch:
diff --git a/mobly/logger.py b/mobly/logger.py
--- a/mobly/logger.py
+++ b/mobly/logger.py
@@ -29,7 +29,7 @@
 log_line_time_format = '%m-%d %H:%M:%S'
 log_line_timestamp_len = 18
 
-logline_timestamp_re = re.compile('\d\d-\d\d \d\d:\d\d:\d\d.\d\d\d')
+logline_timestamp_re = re.compile(r'\d\d-\d\d \d\d:\d\d:\d\d.\d\d\d')
 
 
 def _parse_logline_timestamp(t):


Test patch:
diff --git a/tests/mobly/controllers/android_device_test.py b/tests/mobly/controllers/android_device_test.py
--- a/tests/mobly/controllers/android_device_test.py
+++ b/tests/mobly/controllers/android_device_test.py
@@ -188,7 +188,7 @@ def test_get_device_no_match(self):
     def test_get_device_too_many_matches(self):
         ads = mock_android_device.get_mock_ads(5)
         target_serial = ads[1].serial = ads[0].serial
-        expected_msg = "More than one device matched: \['0', '0'\]"
+        expected_msg = r"More than one device matched: \['0', '0'\]"
         with self.assertRaisesRegex(android_device.Error, expected_msg):
             android_device.get_device(ads, serial=target_serial)
 
diff --git a/tests/mobly/logger_test.py b/tests/mobly/logger_test.py
--- a/tests/mobly/logger_test.py
+++ b/tests/mobly/logger_test.py
@@ -27,6 +27,18 @@ def test_epoch_to_log_line_timestamp(self):
             1469134262116, time_zone=pytz.utc)
         self.assertEqual("07-21 20:51:02.116", actual_stamp)
 
+    def test_is_valid_logline_timestamp(self):
+        self.assertTrue(
+            logger.is_valid_logline_timestamp("06-21 17:44:42.336"))
+
+    def test_is_valid_logline_timestamp_when_wrong_lenght(self):
+        self.assertFalse(
+            logger.is_valid_logline_timestamp("  06-21 17:44:42.336"))
+
+    def test_is_valid_logline_timestamp_when_invalid_content(self):
+        self.assertFalse(
+            logger.is_valid_logline_timestamp("------------------"))
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/mobly/test_runner_test.py b/tests/mobly/test_runner_test.py
--- a/tests/mobly/test_runner_test.py
+++ b/tests/mobly/test_runner_test.py
@@ -259,8 +259,8 @@ def test_teardown_logger_before_setup_logger(self):
         tr = test_runner.TestRunner(self.log_dir, self.test_bed_name)
         with self.assertRaisesRegex(
                 test_runner.Error,
-                'TestRunner\._teardown_logger\(\) called before '
-                'TestRunner\.setup_logger\(\)!'):
+                r'TestRunner\._teardown_logger\(\) called before '
+                r'TestRunner\.setup_logger\(\)!'):
             tr._teardown_logger()
 
     def test_run_no_tests(self):