-
Notifications
You must be signed in to change notification settings - Fork 12
Feature/unittest 2 #30
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
Open
raviinfo173
wants to merge
12
commits into
develop
Choose a base branch
from
feature/unittest_2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c43136
Adding tests
raviinfo173 a1fa1ae
Updating requirements.txt
raviinfo173 b0fd389
Updating requirements.txt
raviinfo173 da3a7a7
Updating requirements.txt
raviinfo173 dd3c668
Updating requirements.txt
raviinfo173 2234b0c
Updating requirements.txt
raviinfo173 8a5a1a1
Updating requirements.txt
raviinfo173 f46e6b7
Updating sys module
raviinfo173 033922d
Updating local with added new changes
raviinfo173 1f88376
Showing only relevant changes.
raviinfo173 8d0ef58
Showing only relevant changes.
raviinfo173 9e2e83f
Showing only relevant changes.
raviinfo173 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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
Empty file.
This file contains hidden or 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,57 @@ | ||
| import time | ||
| import unittest | ||
|
|
||
| from unittest import mock | ||
| import sys | ||
| from unittest.mock import patch | ||
|
|
||
| from tracking.Monitor import GPUCalculator | ||
|
|
||
| redis_mock = mock.MagicMock() | ||
| sys.modules['redis'] = redis_mock | ||
|
|
||
|
|
||
| class TestMonitor(unittest.TestCase): | ||
| """ | ||
| This class tests the Monitor functionalities. | ||
| """ | ||
| def test_MMTMonitor_starttimer(self): | ||
| redis_mock = mock.MagicMock() | ||
| import tracking.Monitor as monitor | ||
| obj = monitor.MMTMonitor(redis_mock, 'key') | ||
| obj.start_timer() | ||
| self.assertIsNotNone(obj.start_time) | ||
|
|
||
| def test_MMTMonitor_with_latency(self): | ||
| redis_mock = mock.MagicMock() | ||
| import tracking.Monitor as monitor | ||
| obj = monitor.MMTMonitor(redis_mock, 'key') | ||
| obj.start_timer() | ||
| time.sleep(1) | ||
| obj.end_timer() | ||
| print(obj.average_latency) | ||
| self.assertNotEqual(obj.average_latency, 0.0) | ||
|
|
||
| def test_MMTMonitor_counter_15(self): | ||
| redis_mock = mock.MagicMock() | ||
| import tracking.Monitor as monitor | ||
| obj = monitor.MMTMonitor(redis_mock, 'key') | ||
| obj.start_timer() | ||
| obj.counter = 14 | ||
| obj.end_timer() | ||
| print(obj.average_latency) | ||
| self.assertEqual(obj.average_latency, 0) | ||
|
|
||
| def test_GPUCalculator(self): | ||
| gpu_calculator = GPUCalculator(redis_mock) | ||
| gpu_calculator.add() | ||
| self.assertEqual(gpu_calculator.count, 1) | ||
|
|
||
| @patch('tracking.Monitor.subprocess') | ||
| def test_GPUCalculator_with_count_15(self, mock_sub): | ||
| output = '1, 2, 3, 4, 5'.encode('utf-8') | ||
| mock_sub.check_output.return_value = output | ||
| gpu_calculator = GPUCalculator(redis_mock) | ||
| gpu_calculator.count = 14 | ||
| gpu_calculator.add() | ||
| self.assertEqual(gpu_calculator.count, 15) |
This file contains hidden or 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,75 @@ | ||
| import argparse | ||
|
|
||
| import pickle | ||
| import unittest | ||
|
|
||
| from unittest import mock | ||
| import sys | ||
| from unittest.mock import patch | ||
|
|
||
| import numpy as np | ||
|
|
||
| arg_mock = mock.MagicMock() | ||
| redis_mock = mock.MagicMock() | ||
| sys.modules['redis'] = redis_mock | ||
| sys.modules['argparse'] = arg_mock | ||
| sys.modules['redis'] = redis_mock | ||
|
|
||
| sys.modules['mmtracking'] = arg_mock | ||
| sys.modules['mmtracking.mmtrack'] = arg_mock | ||
| sys.modules['mmtracking.mmtrack.apis'] = arg_mock | ||
|
|
||
| import tracking.tracker as tracker | ||
|
|
||
|
|
||
| class TestTracker(unittest.TestCase): | ||
| """ | ||
| This class tests the tracker functionalities. | ||
| """ | ||
| @patch('tracking.tracker.results2outs') | ||
| def test_main_with_no_infile(self, mock_results): | ||
| ids_mock = mock.MagicMock() | ||
| mock_results.return_value = ids_mock | ||
| ids_mock.get.return_value = (1, 2, 3) | ||
| redis_mock2 = mock.MagicMock() | ||
| redis_mock.Redis.return_value = redis_mock2 | ||
| redis_mock2.ping.return_value = True | ||
| redis_mock2.xadd.side_effect = [1, Exception] | ||
| img = np.array([[[62, 62, 62], [61, 61, 61], [63, 63, 63]]]) | ||
| msg = { | ||
| b'frameId': '1'.encode('utf-8'), | ||
| b'image': pickle.dumps(img) | ||
| } | ||
| redis_mock2.xread.return_value = [(1, [(1, msg)])] | ||
| arg_mock2 = mock.MagicMock() | ||
| arg_mock.ArgumentParser.return_value = arg_mock2 | ||
| arg_mock2.parse_args.return_value = argparse.Namespace(input_stream='camera:0', classId='PERSON', | ||
| output_stream='camera:0:mot', | ||
| checkpoint='', | ||
| device='cuda:0', | ||
| redis='redis://127.0.0.1:6379', | ||
| maxlen=3000, | ||
| config='') | ||
| with self.assertRaises(Exception): | ||
| tracker.main() | ||
|
|
||
| def test_results2outs_error(self): | ||
| bbox = np.zeros((0, 4), dtype=np.float32), np.zeros((0, 4), dtype=np.float32) | ||
| with self.assertRaises(NotImplementedError): | ||
| tracker.results2outs(bbox, bbox, bbox) | ||
|
|
||
| def test_results2outs_5(self): | ||
| bbox = np.ones((1, 5), dtype=np.float32), np.ones((1, 5), dtype=np.float32) | ||
| actual_response = tracker.results2outs(bbox, bbox, bbox) | ||
| self.assertEqual(actual_response['labels'].size, np.array([0, 1], dtype=np.int64).size) | ||
|
|
||
| def test_results2outs_6(self): | ||
| bbox = np.ones((1, 6), dtype=np.float32), np.ones((1, 6), dtype=np.float32) | ||
| actual_response = tracker.results2outs(bbox, bbox, bbox) | ||
| self.assertEqual(actual_response['labels'].size, np.array([0, 1], dtype=np.int64).size) | ||
|
|
||
| def test_results2outs_masks(self): | ||
| bbox = np.ones((1, 6), dtype=np.float32), np.ones((1, 6), dtype=np.float32) | ||
| actual_response = tracker.results2outs(bbox, bbox, (np.zeros((0, 6), dtype=np.float32),np.zeros((0, 6), dtype=np.float32))) | ||
| self.assertEqual(actual_response['labels'].size, np.array([0, 1], dtype=np.int64).size) | ||
|
|
Empty file.
Empty file.
This file contains hidden or 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,48 @@ | ||
| import json | ||
|
|
||
| import unittest | ||
| from tracklet.tracklet import Tracklet | ||
|
|
||
|
|
||
| class TestTracklet(unittest.TestCase): | ||
| """ This class tests the tracklet functionalities. """ | ||
|
|
||
| def test_add_box(self): | ||
| obj = Tracklet('', '') | ||
| obj.add_box(-1) | ||
| obj.add_box(-1) | ||
| obj.add_box(-1) | ||
| obj.add_box(-1) | ||
| obj.add_box(-1) | ||
| self.assertEqual(obj._boxes, [-1, -1, -1, -1, -1]) | ||
|
|
||
| def test_increase_skip(self): | ||
| from tracklet.tracklet import Tracklet | ||
| obj = Tracklet('', '') | ||
| obj.increase_skip() | ||
| self.assertEqual(obj._skipped_frames, 1) | ||
|
|
||
| def test_skipped_frames(self): | ||
| from tracklet.tracklet import Tracklet | ||
| obj = Tracklet('', '') | ||
| self.assertEqual(obj.skipped_frames, 0) | ||
|
|
||
| def test_objectId(self): | ||
| from tracklet.tracklet import Tracklet | ||
| obj = Tracklet('', '') | ||
| self.assertEqual(obj.objectId, '') | ||
|
|
||
| def test_object_class(self): | ||
| from tracklet.tracklet import Tracklet | ||
| obj = Tracklet('', '') | ||
| self.assertEqual(obj.object_class, '') | ||
|
|
||
| def test__repr__(self): | ||
| from tracklet.tracklet import Tracklet | ||
| obj = Tracklet('', '') | ||
| res = obj.__repr__() | ||
| self.assertEqual(json.loads(res), { | ||
| "object_id": "", | ||
| "boxes": [], | ||
| "skipped_frames": "0" | ||
| }) |
This file contains hidden or 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,18 @@ | ||
| import unittest | ||
|
|
||
| from tracklet.trackletmanager import TrackletManager | ||
|
|
||
|
|
||
| class TestTrackletManager(unittest.TestCase): | ||
| """ | ||
| This class tests the trackletmanager functionalities. | ||
| """ | ||
| def test_process_objects_active(self): | ||
| obj = TrackletManager(3) | ||
| res = obj.process_objects({'a': 1, 'b': 2}) | ||
| self.assertEqual(res, {'a': 'active', 'b': 'active'}) | ||
|
|
||
| def test_process_objects_inactive(self): | ||
| obj = TrackletManager(1) | ||
| res = obj.process_objects({'a': None}) | ||
| self.assertEqual(res, {'a': 'inactive'}) |
Empty file.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,75 @@ | ||
| import sys | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| arg_mock = mock.MagicMock() | ||
| redis_mock = mock.MagicMock() | ||
| sys.modules['redis'] = redis_mock | ||
| sys.modules['argparse'] = arg_mock | ||
|
|
||
| import producer | ||
|
|
||
|
|
||
| class TestProducer(unittest.TestCase): | ||
| """ | ||
| This class tests the producer functionalities. | ||
| """ | ||
| def test_main_with_infile(self): | ||
| redis_mock2 = mock.MagicMock() | ||
| redis_mock.Redis.return_value = redis_mock2 | ||
| redis_mock2.ping.return_value = True | ||
| arg_mock2 = mock.MagicMock() | ||
| arg_mock.ArgumentParser.return_value = arg_mock2 | ||
| arg_mock3 = mock.MagicMock() | ||
| arg_mock2.parse_args.return_value = arg_mock3 | ||
| arg_mock3.url = 'redis://127.0.0.1:6379' | ||
| arg_mock3.infile = 'data/race.mp4' | ||
| arg_mock3.output = 'camera:0' | ||
| arg_mock3.webcam = 0 | ||
| arg_mock3.verbose = False | ||
| arg_mock3.count = 5 | ||
| arg_mock3.fmt = '.jpg' | ||
| arg_mock3.inputFps = 30.0 | ||
| arg_mock3.maxlen = 3000 | ||
| arg_mock3.outputFps = 10.0 | ||
| res = producer.main() | ||
| self.assertIsNone(res) | ||
|
|
||
| def test_main_exception(self): | ||
| redis_mock2 = mock.MagicMock() | ||
| redis_mock.Redis.return_value = redis_mock2 | ||
| redis_mock2.ping.return_value = False | ||
| arg_mock2 = mock.MagicMock() | ||
| arg_mock.ArgumentParser.return_value = arg_mock2 | ||
| arg_mock3 = mock.MagicMock() | ||
| arg_mock2.parse_args.return_value = arg_mock3 | ||
| arg_mock3.url = 'redis://127.0.0.1:6379' | ||
| arg_mock3.infile = 'data/race.mp4' | ||
| arg_mock3.output = 'camera:0' | ||
| arg_mock3.webcam = 0 | ||
| arg_mock3.verbose = False | ||
| arg_mock3.count = 5 | ||
| arg_mock3.fmt = '.jpg' | ||
| arg_mock3.inputFps = 30.0 | ||
| arg_mock3.maxlen = 3000 | ||
| arg_mock3.outputFps = 10.0 | ||
| with self.assertRaises(Exception): | ||
| producer.main() | ||
|
|
||
| def test_video_sample_rate(self): | ||
| obj = producer.Video(0, 30) | ||
| res = obj.video_sample_rate(30) | ||
| self.assertEqual(res, 1) | ||
|
|
||
| def test_cam_release(self): | ||
| obj = producer.Video(0, 30) | ||
| res = obj.cam_release() | ||
| self.assertIsNone(res) | ||
|
|
||
| def test___iter__(self): | ||
| obj = producer.Video(0, 30) | ||
| res = obj.__iter__() | ||
| self.assertEqual(res.count, -1) | ||
| res1 = obj.__len__() | ||
| self.assertEqual(res1, 0) | ||
| obj.isFile = True |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.