-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert handles and requests to new base module
- Loading branch information
Showing
24 changed files
with
1,123 additions
and
724 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2016, Maximilian Köhl <mail@koehlma.de> | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License version 3 as published by | ||
# the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import print_function, unicode_literals, division, absolute_import | ||
|
||
import os | ||
import os.path | ||
import tempfile | ||
|
||
from common import TestCase | ||
|
||
import uv | ||
|
||
|
||
class TestFSEvent(TestCase): | ||
def test_fs_event_change(self): | ||
def on_event(fs_event, status, name, events): | ||
self.assert_equal(status, uv.error.StatusCodes.SUCCESS) | ||
self.assert_equal(name, os.path.basename(self.temp_file.name)) | ||
self.assert_equal(events, uv.FSEvents.CHANGE) | ||
fs_event.close() | ||
|
||
def on_timeout(timer): | ||
self.temp_file.write(b'x') | ||
self.temp_file.flush() | ||
timer.close() | ||
|
||
self.fs_event = uv.FSEvent(on_event=on_event) | ||
self.timer = uv.Timer(on_timeout=on_timeout) | ||
|
||
with tempfile.NamedTemporaryFile() as temp_file: | ||
self.temp_file = temp_file | ||
self.fs_event.path = temp_file.name | ||
self.fs_event.start() | ||
self.timer.start(20) | ||
self.loop.run() | ||
|
||
def test_fs_event_rename(self): | ||
def on_event(fs_event, status, name, events): | ||
self.assert_equal(status, uv.error.StatusCodes.SUCCESS) | ||
self.assert_equal(name, os.path.basename(self.temp_file.name)) | ||
self.assert_equal(events, uv.FSEvents.RENAME) | ||
fs_event.close() | ||
|
||
def on_timeout(timer): | ||
os.rename(self.temp_file.name, self.temp_file.name + '-new-name') | ||
timer.close() | ||
|
||
self.fs_event = uv.FSEvent(on_event=on_event) | ||
self.timer = uv.Timer(on_timeout=on_timeout) | ||
|
||
with tempfile.NamedTemporaryFile() as temp_file: | ||
self.temp_file = temp_file | ||
self.fs_event.path = temp_file.name | ||
self.fs_event.start() | ||
self.timer.start(20) | ||
self.loop.run() | ||
os.rename(self.temp_file.name + '-new-name', self.temp_file.name) | ||
|
||
def test_fs_event_stop(self): | ||
self.fs_event = uv.FSEvent() | ||
|
||
with tempfile.NamedTemporaryFile() as temp_file: | ||
self.fs_event.path = temp_file.name | ||
self.fs_event.start() | ||
self.fs_event.stop() | ||
self.loop.run() |
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,54 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2016, Maximilian Köhl <mail@koehlma.de> | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License version 3 as published by | ||
# the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import print_function, unicode_literals, division, absolute_import | ||
|
||
import tempfile | ||
|
||
from common import TestCase | ||
|
||
import uv | ||
|
||
|
||
class TestFSPoll(TestCase): | ||
def test_fs_poll_change(self): | ||
def on_change(fs_poll, status, previous_stat, current_stat): | ||
self.assert_equal(status, uv.error.StatusCodes.SUCCESS) | ||
self.assert_not_equal(previous_stat.mtim, current_stat.mtim) | ||
fs_poll.close() | ||
|
||
def on_timeout(timer): | ||
self.temp_file.write(b'x') | ||
self.temp_file.flush() | ||
timer.close() | ||
|
||
self.fs_poll = uv.FSPoll(interval=2000, on_change=on_change) | ||
self.timer = uv.Timer(on_timeout=on_timeout) | ||
|
||
with tempfile.NamedTemporaryFile() as temp_file: | ||
self.temp_file = temp_file | ||
self.fs_poll.path = temp_file.name | ||
self.fs_poll.start() | ||
self.timer.start(1000) | ||
self.loop.run() | ||
|
||
def test_fs_poll_stop(self): | ||
self.fs_poll = uv.FSPoll() | ||
|
||
with tempfile.NamedTemporaryFile() as temp_file: | ||
self.fs_poll.path = temp_file.name | ||
self.fs_poll.start() | ||
self.fs_poll.stop() | ||
self.loop.run() |
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,51 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2016, Maximilian Köhl <mail@koehlma.de> | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License version 3 as published by | ||
# the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import print_function, unicode_literals, division, absolute_import | ||
|
||
import gc | ||
import weakref | ||
|
||
from common import TestCase, implementation_skip | ||
|
||
import uv | ||
|
||
|
||
@implementation_skip('pypy') | ||
class TestGC(TestCase): | ||
def test_gc_loop(self): | ||
loop = uv.Loop() | ||
weak_loop = weakref.ref(loop) | ||
base_loop = weakref.ref(loop.base_loop) | ||
del loop | ||
gc.collect() | ||
self.assert_not_equal(weak_loop(), None) | ||
self.assert_not_equal(base_loop(), None) | ||
uv.Loop._thread_locals.loop = None | ||
gc.collect() | ||
self.assert_equal(weak_loop(), None) | ||
self.assert_equal(base_loop(), None) | ||
|
||
def test_gc_handle(self): | ||
weak_handle = weakref.ref(uv.Prepare()) | ||
gc.collect() | ||
self.assert_equal(weak_handle(), None) | ||
prepare = uv.Prepare() | ||
prepare.start() | ||
weak_handle = weakref.ref(prepare) | ||
del prepare | ||
gc.collect() | ||
self.assert_not_equal(weak_handle(), None) | ||
|
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
Oops, something went wrong.