-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a stub class and singleton to represent main
This is an updated patch from pull request #16 which will throw an exception if coro is called without starting the event_loop(). The main update is to bring it up to date with recent changes and make the linux poller throw the correct exception in this case.
- Loading branch information
Showing
6 changed files
with
71 additions
and
28 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
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
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,16 @@ | ||
import coro | ||
import unittest | ||
|
||
class CoroMain(unittest.TestCase): | ||
def test_coro_main_connect(self): | ||
s = coro.tcp_sock() | ||
with self.assertRaises(coro.YieldFromMain): | ||
s.connect (('127.0.0.1', 80)) | ||
|
||
def test_coro_main_yield(self): | ||
s = coro.tcp_sock() | ||
with self.assertRaises(coro.YieldFromMain): | ||
coro.yield_slice() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,21 @@ | ||
import coro | ||
import unittest | ||
|
||
def exit_coro(): | ||
coro.sleep_relative(0.1) | ||
coro.set_exit() | ||
|
||
|
||
class CoroMain(unittest.TestCase): | ||
def test_coro_main(self): | ||
coro.set_print_exit_string(None) | ||
|
||
for x in range(4): | ||
try: | ||
coro.spawn(exit_coro) | ||
coro.event_loop() | ||
except SystemExit: | ||
pass | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |