#!/usr/bin/env python2
import subprocess
import os
import sys
import argparse
import tempfile
getting ready for Python 3 (#619)
* tabs to spaces
python 2 to 3: https://portingguide.readthedocs.io/en/latest/syntax.html#tabs-and-spaces
* use the new except syntax
python 2 to 3: https://portingguide.readthedocs.io/en/latest/exceptions.html#the-new-except-syntax
* make relative imports absolute
python 2 to 3: https://portingguide.readthedocs.io/en/latest/imports.html#absolute-imports
* Queue renamed to queue in python 3
Use the six compatibility library to support both python 2 and 3: https://portingguide.readthedocs.io/en/latest/stdlib-reorg.html#renamed-modules
* replace dict.has_key() with in
python 2 to 3: https://portingguide.readthedocs.io/en/latest/dicts.html#removed-dict-has-key
* make dict views compatible with python 3
python 2 to 3: https://portingguide.readthedocs.io/en/latest/dicts.html#dict-views-and-iterators
Where needed, wrapping things that will be a view in python 3 with a list(). For example, if it's accessed with []
Python 3 has no iter*() methods, so just using the values() instead of itervalues() as long as it's not too performance intensive. Note that any minor performance hit of using a list instead of a view will go away when switching to python 3. If it is intensive, we could use the six version.
* Explicitly use truncating division
python 2 to 3: https://portingguide.readthedocs.io/en/latest/numbers.html#division
python 3 treats / as float division. When we want the result to be an integer, use //
* replace map() with list comprehension where a list result is needed.
In python 3, map() returns an iterator.
python 2 to 3: https://portingguide.readthedocs.io/en/latest/iterators.html#new-behavior-of-map-and-filter
* replace filter() with list comprehension
In python 3, filter() returns an interatoooooooooooor.
python 2 to 3: https://portingguide.readthedocs.io/en/latest/iterators.html#new-behavior-of-map-and-filter
* wrap zip() in list() where we need the result to be a list
python 2 to 3: https://portingguide.readthedocs.io/en/latest/iterators.html#new-behavior-of-zip
* clean out some lint
Removes these pylint warnings:
************* Module selfdrive.car.chrysler.chryslercan
W: 15, 0: Unnecessary semicolon (unnecessary-semicolon)
W: 16, 0: Unnecessary semicolon (unnecessary-semicolon)
W: 25, 0: Unnecessary semicolon (unnecessary-semicolon)
************* Module common.dbc
W:101, 0: Anomalous backslash in string: '\?'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
************* Module selfdrive.car.gm.interface
R:102, 6: Redefinition of ret.minEnableSpeed type from float to int (redefined-variable-type)
R:103, 6: Redefinition of ret.mass type from int to float (redefined-variable-type)
************* Module selfdrive.updated
R: 20, 6: Redefinition of r type from int to str (redefined-variable-type)
6 years ago
from selfdrive . locationd . test . ubloxd_py_test import parser_test
from selfdrive . locationd . test . ubloxd_regression_test import compare_results
def mkdirs_exists_ok ( path ) :
try :
os . makedirs ( path )
except OSError :
if not os . path . isdir ( path ) :
raise
def main ( args ) :
cur_dir = os . path . dirname ( os . path . realpath ( __file__ ) )
ubloxd_dir = os . path . join ( cur_dir , ' ../ ' )
cc_output_dir = os . path . join ( args . output_dir , ' cc ' )
mkdirs_exists_ok ( cc_output_dir )
py_output_dir = os . path . join ( args . output_dir , ' py ' )
mkdirs_exists_ok ( py_output_dir )
archive_file = os . path . join ( cur_dir , args . stream_gz_file )
try :
print ( ' Extracting stream file ' )
subprocess . check_call ( [ ' tar ' , ' zxf ' , archive_file ] , cwd = tempfile . gettempdir ( ) )
stream_file_path = os . path . join ( tempfile . gettempdir ( ) , ' ubloxRaw.stream ' )
if not os . path . isfile ( stream_file_path ) :
print ( ' Extract file failed ' )
sys . exit ( - 3 )
print ( ' Compiling test app... ' )
subprocess . check_call ( [ " make " , " ubloxd_test " ] , cwd = ubloxd_dir )
print ( ' Run regression test - CC parser... ' )
if args . valgrind :
subprocess . check_call ( [ " valgrind " , " --leak-check=full " , os . path . join ( ubloxd_dir , ' ubloxd_test ' ) , stream_file_path , cc_output_dir ] )
else :
subprocess . check_call ( [ os . path . join ( ubloxd_dir , ' ubloxd_test ' ) , stream_file_path , cc_output_dir ] )
print ( ' Running regression test - py parser... ' )
parser_test ( stream_file_path , py_output_dir )
print ( ' Running regression test - compare result... ' )
r = compare_results ( cc_output_dir , py_output_dir )
print ( ' All done! ' )
subprocess . check_call ( [ " rm " , stream_file_path ] )
subprocess . check_call ( [ " rm " , ' -rf ' , cc_output_dir ] )
subprocess . check_call ( [ " rm " , ' -rf ' , py_output_dir ] )
sys . exit ( r )
except subprocess . CalledProcessError as e :
print ( ' CI test failed with {} ' . format ( e . returncode ) )
sys . exit ( e . returncode )
if __name__ == " __main__ " :
parser = argparse . ArgumentParser ( description = " Ubloxd CI test " ,
formatter_class = argparse . ArgumentDefaultsHelpFormatter )
parser . add_argument ( " stream_gz_file " , nargs = ' ? ' , default = ' ubloxRaw.tar.gz ' ,
help = " UbloxRaw data stream zip file " )
parser . add_argument ( " output_dir " , nargs = ' ? ' , default = ' out ' ,
help = " Output events temp directory " )
parser . add_argument ( " --valgrind " , default = False , action = ' store_true ' ,
help = " Run in valgrind " )
args = parser . parse_args ( )
main ( args )