-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3106db3
commit 7213988
Showing
5 changed files
with
102 additions
and
4 deletions.
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
{ | ||
"python.analysis.typeCheckingMode": "basic", | ||
"python.tensorBoard.logDirectory": "./logs" | ||
"python.testing.unittestArgs": [ | ||
"-v", | ||
"-s", | ||
"./src/pyramid-test", | ||
"-p", | ||
"*_test.py" | ||
], | ||
"python.testing.pytestEnabled": false, | ||
"python.testing.unittestEnabled": true | ||
} |
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,6 @@ | ||
import unittest | ||
import queue_test | ||
|
||
if __name__ == "__main__": | ||
suite = unittest.TestLoader().loadTestsFromModule(queue_test) | ||
unittest.TextTestRunner(verbosity=2).run(suite) |
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,68 @@ | ||
|
||
import os | ||
import sys | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
|
||
from pyramid.tools.queue import Queue, QueueItem # noqa: E402 | ||
|
||
|
||
class TestQueue(unittest.TestCase): | ||
def test_add(self): | ||
queue = Queue(threads=1) | ||
self.assertEqual(queue.length(), 0) | ||
|
||
item = QueueItem(name="test", func=lambda x: x, x=5) | ||
queue.add(item) | ||
self.assertEqual(queue.length(), 1) | ||
|
||
def test_add_at_start(self): | ||
queue = Queue(threads=1) | ||
self.assertEqual(queue.length(), 0) | ||
|
||
item = QueueItem(name="test", func=lambda x: x, x=5) | ||
queue.add_at_start(item) | ||
self.assertEqual(queue.length(), 1) | ||
|
||
def test_worker_start_before(self): | ||
queue = Queue(threads=1) | ||
self.assertEqual(queue.length(), 0) | ||
|
||
queue.start() | ||
item = QueueItem(name="test", func=lambda x: x, x=5) | ||
queue.add(item) | ||
self.assertEqual(queue.length(), 1) | ||
|
||
queue.end() | ||
queue.join() | ||
self.assertEqual(queue.length(), 0) | ||
|
||
def test_worker_start_after(self): | ||
queue = Queue(threads=1) | ||
self.assertEqual(queue.length(), 0) | ||
|
||
item = QueueItem(name="test", func=lambda x: x, x=5) | ||
queue.add(item) | ||
self.assertEqual(queue.length(), 1) | ||
|
||
queue.start() | ||
queue.end() | ||
queue.join() | ||
self.assertEqual(queue.length(), 0) | ||
|
||
def test_wait_for_end(self): | ||
queue = Queue(threads=1) | ||
queue.register_to_wait_on_exit() | ||
queue.start() | ||
|
||
item = QueueItem(name="test", func=lambda x: x, x=5) | ||
queue.add(item) | ||
|
||
with patch.object(Queue, 'join') as mock_join: | ||
Queue.wait_for_end(timeout_per_threads=5) | ||
mock_join.assert_called_with(5) | ||
|
||
if __name__ == "__main__": | ||
unittest.main(failfast=True) |
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 @@ | ||
name = "pyramid" |