Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions unit-tests/py/rspy/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
# Copyright(c) 2021 Intel Corporation. All Rights Reserved.

from rspy import log
import sys, os

# We need both pyrealsense2 and acroname. We can work without acroname, but
# without rs no devices at all will be returned.
try:
import pyrealsense2 as rs
log.d( rs )
#
# Have to add site-packages, just in case: if -S was used, or parent script played with
# sys.path (as run-unit-tests does), then we may not have it!
sys.path += [os.path.join( os.path.dirname( sys.executable ), 'lib', 'site-packages')]
#
try:
from rspy import acroname
except ModuleNotFoundError:
# Error should have already been printed
# We assume there's no brainstem library, meaning no acroname either
log.d( 'sys.path=', sys.path )
acroname = None
#
sys.path = sys.path[:-1] # remove what we added
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to use a third party lib like numpy in our test it will not work right?
If yes, than we need to think of another way to solve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it won't work (unless numpy isn't in site-packages) unless the module is in lib/.
One thing I can do is remove site-packages before loading librealsense, but it's hard to control when a script imports pyrs.
For now, it'll work.

except ModuleNotFoundError:
log.w( 'No pyrealsense2 library is available! Running as if no cameras available...' )
import sys
Expand Down
20 changes: 12 additions & 8 deletions unit-tests/run-unit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# otherwise pyrs other than what we compiled might be found...
sys.path = list()
sys.path.append( '' ) # directs Python to search modules in the current directory first
sys.path.append( os.path.dirname( sys.executable ))
sys.path.append( os.path.join( os.path.dirname( sys.executable ), 'DLLs' ))
sys.path.append( os.path.join( os.path.dirname( sys.executable ), 'lib' ))
# Add our py/ module directory
current_dir = os.path.dirname( os.path.abspath( __file__ ))
sys.path.append( current_dir + os.sep + "py" )
Expand Down Expand Up @@ -194,7 +197,7 @@ def grep( expr, *args ):
context['filename'] = filename
with open( filename, errors = 'ignore' ) as file:
for line in grep_( pattern, remove_newlines( file ), context ):
yield context
yield line

def cat( filename ):
with open( filename, errors = 'ignore' ) as file:
Expand Down Expand Up @@ -279,16 +282,16 @@ def __init__( self, source, line_prefix ):
if directive == 'device':
log.d( ' configuration:', params )
if not params:
log.e( source + '+' + str(context.index) + ': device directive with no devices listed' )
log.e( source + '+' + str(context['index']) + ': device directive with no devices listed' )
else:
self._configurations.append( params )
elif directive == 'priority':
if len(params) == 1 and params[0].isdigit():
self._priority = int( params[0] )
else:
log.e( source + '+' + str(context.index) + ': priority directive with invalid parameters:', params )
log.e( source + '+' + str(context['index']) + ': priority directive with invalid parameters:', params )
else:
log.e( source + '+' + str(context.index) + ': invalid directive "' + directive + '"; ignoring' )
log.e( source + '+' + str(context['index']) + ': invalid directive "' + directive + '"; ignoring' )


class Test(ABC): # Abstract Base Class
Expand Down Expand Up @@ -503,10 +506,11 @@ def devices_by_test_config( test ):
def test_wrapper( test, configuration = None ):
global n_tests
n_tests += 1
if configuration:
log.progress( '[' + ' '.join( configuration ) + ']', test.name, '...' )
else:
log.progress( test.name, '...' )
if not log.is_debug_on() or log.is_color_on():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the color check?
Not just debug check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If color is on, then the terminal supports advanced controls and progress will not stay on-screen. I wanted to avoid the progress since debug includes the same information, for readability on the libci logs. But when I run it locally, I run with debug and I have color, so it still shows progress...

if configuration:
log.progress( '[' + ' '.join( configuration ) + ']', test.name, '...' )
else:
log.progress( test.name, '...' )
test.run_test()


Expand Down