-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests for cuerqd.py. #490
Merged
bcipriano
merged 1 commit into
AcademySoftwareFoundation:master
from
bcipriano:cuerqd-tests
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (c) 2018 Sony Pictures Imageworks Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import mock | ||
import sys | ||
import unittest | ||
|
||
import rqd.cuerqd | ||
import rqd.compiled_proto.rqd_pb2 | ||
|
||
|
||
SCRIPT_NAME = '/arbitrary/path/to/script' | ||
RQD_HOSTNAME = 'arbitrary-rqd-hostname' | ||
|
||
|
||
@mock.patch('rqd.compiled_proto.rqd_pb2_grpc.RunningFrameStub') | ||
@mock.patch('rqd.compiled_proto.rqd_pb2_grpc.RqdInterfaceStub') | ||
@mock.patch('grpc.insecure_channel', new=mock.MagicMock()) | ||
class CueRqdTests(unittest.TestCase): | ||
|
||
@mock.patch('rqd.cuerqd.RqdHost') | ||
def test_init(self, rqdHostMock, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '-s'] | ||
|
||
rqd.cuerqd.main() | ||
|
||
rqdHostMock.assert_called_with(RQD_HOSTNAME) | ||
|
||
@mock.patch('rqd.cuerqd.RqdHost') | ||
def test_initWithLocalhost(self, rqdHostMock, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, '-s'] | ||
|
||
rqd.cuerqd.main() | ||
|
||
rqdHostMock.assert_called_with('localhost') | ||
|
||
def test_status(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '-s'] | ||
statusRequest = rqd.compiled_proto.rqd_pb2.RqdStaticReportStatusRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.ReportStatus.assert_called_with(statusRequest) | ||
|
||
def test_getRunningFrame(self, stubMock, frameStubMock): | ||
frameId = 'arbitrary-frame-id' | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--getproxy', frameId] | ||
runFrameRequest = rqd.compiled_proto.rqd_pb2.RqdStaticGetRunFrameRequest(frame_id=frameId) | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.GetRunFrame.assert_called_with(runFrameRequest) | ||
|
||
def test_nimbyOff(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--nimbyoff'] | ||
nimbyOffRequest = rqd.compiled_proto.rqd_pb2.RqdStaticNimbyOffRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.NimbyOff.assert_called_with(nimbyOffRequest) | ||
|
||
def test_nimbyOn(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--nimbyon'] | ||
nimbyOnRequest = rqd.compiled_proto.rqd_pb2.RqdStaticNimbyOnRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.NimbyOn.assert_called_with(nimbyOnRequest) | ||
|
||
def test_lockAll(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--lh'] | ||
lockAllRequest = rqd.compiled_proto.rqd_pb2.RqdStaticLockAllRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.LockAll.assert_called_with(lockAllRequest) | ||
|
||
def test_unlockAll(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--ulh'] | ||
unlockAllRequest = rqd.compiled_proto.rqd_pb2.RqdStaticUnlockAllRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.UnlockAll.assert_called_with(unlockAllRequest) | ||
|
||
def test_lock(self, stubMock, frameStubMock): | ||
numCoresToLock = 85 | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--lp', str(numCoresToLock)] | ||
lockRequest = rqd.compiled_proto.rqd_pb2.RqdStaticLockRequest(cores=numCoresToLock) | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.Lock.assert_called_with(lockRequest) | ||
|
||
def test_unlock(self, stubMock, frameStubMock): | ||
numCoresToUnlock = 52 | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--ulp', str(numCoresToUnlock)] | ||
unlockRequest = rqd.compiled_proto.rqd_pb2.RqdStaticUnlockRequest(cores=numCoresToUnlock) | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.Unlock.assert_called_with(unlockRequest) | ||
|
||
def test_shutdownRqdIdle(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--exit'] | ||
shutdownIdleRequest = rqd.compiled_proto.rqd_pb2.RqdStaticShutdownIdleRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.ShutdownRqdIdle.assert_called_with(shutdownIdleRequest) | ||
|
||
def test_shutdownRqdNow(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--exit_now'] | ||
shutdownNowRequest = rqd.compiled_proto.rqd_pb2.RqdStaticShutdownNowRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.ShutdownRqdNow.assert_called_with(shutdownNowRequest) | ||
|
||
def test_restartRqdIdle(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--restart'] | ||
restartIdleRequest = rqd.compiled_proto.rqd_pb2.RqdStaticRestartIdleRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.RestartRqdIdle.assert_called_with(restartIdleRequest) | ||
|
||
def test_restartRqdNow(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--restart_now'] | ||
restartNowRequest = rqd.compiled_proto.rqd_pb2.RqdStaticRestartNowRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.RestartRqdNow.assert_called_with(restartNowRequest) | ||
|
||
def test_rebootIdle(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--reboot'] | ||
rebootIdleRequest = rqd.compiled_proto.rqd_pb2.RqdStaticRebootIdleRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.RebootIdle.assert_called_with(rebootIdleRequest) | ||
|
||
def test_rebootNow(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--reboot_now'] | ||
rebootNowRequest = rqd.compiled_proto.rqd_pb2.RqdStaticRebootNowRequest() | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.RebootNow.assert_called_with(rebootNowRequest) | ||
|
||
def test_launchFrame(self, stubMock, frameStubMock): | ||
runFrame = rqd.compiled_proto.rqd_pb2.RunFrame() | ||
runFrame.job_id = "SD6F3S72DJ26236KFS" | ||
runFrame.job_name = "edu-trn_job-name" | ||
runFrame.frame_id = "FD1S3I154O646UGSNN" | ||
runFrameRequest = rqd.compiled_proto.rqd_pb2.RqdStaticLaunchFrameRequest(run_frame=runFrame) | ||
rqdHost = rqd.cuerqd.RqdHost(RQD_HOSTNAME) | ||
|
||
rqdHost.launchFrame(runFrame) | ||
|
||
stubMock.return_value.LaunchFrame.assert_called_with(runFrameRequest) | ||
|
||
def test_killFrame(self, stubMock, frameStubMock): | ||
frameId = 'arbitrary-frame-id' | ||
runFrame = rqd.compiled_proto.rqd_pb2.RunFrame(frame_id=frameId) | ||
stubMock.return_value.GetRunFrame.return_value = runFrame | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--kill', frameId] | ||
|
||
rqd.cuerqd.main() | ||
|
||
frameStubMock.return_value.Kill.assert_called_with(run_frame=runFrame, message=mock.ANY) | ||
|
||
def test_testEduFrame(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--test_edu_frame'] | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.LaunchFrame.assert_called() | ||
|
||
def test_testScriptFrame(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--test_script_frame'] | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.LaunchFrame.assert_called() | ||
|
||
def test_testScriptFrameMac(self, stubMock, frameStubMock): | ||
sys.argv = [SCRIPT_NAME, RQD_HOSTNAME, '--test_script_frame_mac'] | ||
|
||
rqd.cuerqd.main() | ||
|
||
stubMock.return_value.LaunchFrame.assert_called() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably cleanup this whole bit later on. I added #491 to switch to using something like argparse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I was tempted to just do it here but decided it's best to get tests in place first.