eyeonus / Trade-Dangerous

Mozilla Public License 2.0
98 stars 31 forks source link

remove deprecated escape sequences #107

Closed kmpm closed 1 year ago

kmpm commented 1 year ago

Running tests reveal some deprecation warnings on regex escape sequences. These should be reworked

tests/test_bootstrap_commands.py::TestBootstrapCommands::test_import_update_gui
    D:\a\Trade-Dangerous\Trade-Dangerous\tradedangerous\commands\update_gui.py:698: DeprecationWarning: invalid escape sequence \d
      elif re.match('^\d+$', supply):

  tests/test_bootstrap_plugins.py::TestBootstrapPlugins::test_import_plugins_netlog
    D:\a\Trade-Dangerous\Trade-Dangerous\tradedangerous\plugins\netlog_plug.py:85: DeprecationWarning: invalid escape sequence \d
      oldHeadRegEx = re.compile("^(?P<headDateTime>\d\d-\d\d-\d\d-\d\d:\d\d)\s+(?P<headTZName>.*[^\s])\s+(?P<headTimeGMT>\(.*GMT\))")

  tests/test_bootstrap_plugins.py::TestBootstrapPlugins::test_import_plugins_netlog
    D:\a\Trade-Dangerous\Trade-Dangerous\tradedangerous\plugins\netlog_plug.py:86: DeprecationWarning: invalid escape sequence \d
      newHeadRegEx = re.compile("^(?P<headDateTime>\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d)\s+(?P<headTZName>.*[^\s])")

  tests/test_bootstrap_plugins.py::TestBootstrapPlugins::test_import_plugins_netlog
    D:\a\Trade-Dangerous\Trade-Dangerous\tradedangerous\plugins\netlog_plug.py:88: DeprecationWarning: invalid escape sequence \{
      sysRegEx  = re.compile('^\{[^\}]+\}\s+System:"(?P<sysName>[^"]+)".*StarPos:\((?P<sysPos>[^)]+)\)ly')

  tests/test_bootstrap_plugins.py::TestBootstrapPlugins::test_import_plugins_netlog
    D:\a\Trade-Dangerous\Trade-Dangerous\tradedangerous\plugins\netlog_plug.py:89: DeprecationWarning: invalid escape sequence \{
      dateRegEx = re.compile('^\{(?P<logTime>\d\d:\d\d:\d\d)')
eyeonus commented 1 year ago

From the documentation, it seems like the solution is to change for example '^\d+$' to be r"^\d+$" so that Python doesn't try to parse the escape characters itself.

Assuming all the escapes in the strings are there for the regex, that's not difficult to fix, I'll take care of it tomorrow after I get some sleep.