Skip to content

Commit

Permalink
fix github actions (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
MainRo committed Feb 3, 2021
1 parent 24f3c2d commit 39040a4
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 49 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/pythonpackage.yml
Expand Up @@ -18,18 +18,15 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --select=E9,F63,F7 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest
coverage:
Expand All @@ -42,10 +39,14 @@ jobs:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run coverage
- name: Run coverage tests
run: |
pip install coveralls
coverage run -m pytest && coveralls
coverage run -m pytest
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
run: |
coveralls
3 changes: 3 additions & 0 deletions requirements.txt
@@ -0,0 +1,3 @@
pytest
coveralls
flake8
3 changes: 0 additions & 3 deletions tests/test_observable_multiple.py
Expand Up @@ -51,6 +51,3 @@ def _raise(ex):
# strictEqual(subscribes, 1, "catchException(function): After dispose: 1 subscribes")
# strictEqual(unsubscribes, 1, "catchException(function): After dispose: 1 unsubscribes") // this one FAILS (unsubscribes is 0)
#

if __name__ == '__main__':
test_combine_latest_return_empty()
4 changes: 0 additions & 4 deletions tests/test_observable_time.py
Expand Up @@ -215,7 +215,3 @@ def _raise(ex):


# // TakeLast


if __name__ == '__main__':
test_buffer_with_time_or_count_basic()
6 changes: 3 additions & 3 deletions tests/test_scheduler/test_currentthreadscheduler.py
Expand Up @@ -52,14 +52,14 @@ class MyScheduler(CurrentThreadScheduler):
def test_currentthread_now(self):
scheduler = CurrentThreadScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) < timedelta(milliseconds=5)

def test_currentthread_now_units(self):
scheduler = CurrentThreadScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_currentthread_schedule(self):
scheduler = CurrentThreadScheduler()
Expand Down
27 changes: 24 additions & 3 deletions tests/test_scheduler/test_eventloopscheduler.py
Expand Up @@ -15,14 +15,14 @@ class TestEventLoopScheduler(unittest.TestCase):
def test_event_loop_now(self):
scheduler = EventLoopScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) < timedelta(milliseconds=5)

def test_event_loop_now_units(self):
scheduler = EventLoopScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_event_loop_schedule_action(self):
scheduler = EventLoopScheduler(exit_if_empty=True)
Expand All @@ -37,6 +37,9 @@ def action(scheduler, state):
scheduler.schedule(action)
gate.acquire()
assert ran is True
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
assert scheduler._has_thread() is False

def test_event_loop_different_thread(self):
Expand All @@ -51,6 +54,9 @@ def action(scheduler, state):

scheduler.schedule(action)
gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
assert thread_id != threading.current_thread().ident
assert scheduler._has_thread() is False

Expand All @@ -67,6 +73,9 @@ def action(scheduler, state):

scheduler.schedule(action)
gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
assert result == [1, 2]
assert scheduler._has_thread() is False

Expand All @@ -84,6 +93,9 @@ def action(scheduler, state):
scheduler.schedule(lambda s, t: result.append(1))

gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
assert result == [1, 2, 3]
assert scheduler._has_thread() is False

Expand All @@ -107,6 +119,9 @@ def action3(scheduler, state):
scheduler.schedule(action)

gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
assert result == [1, 2, 3]
assert scheduler._has_thread() is False

Expand All @@ -123,6 +138,9 @@ def action(scheduler, state):

scheduler.schedule_relative(timedelta(milliseconds=200), action)
gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
diff = endtime - starttime
assert diff > timedelta(milliseconds=180)
assert scheduler._has_thread() is False
Expand All @@ -140,6 +158,9 @@ def action(scheduler, state):

scheduler.schedule_absolute(scheduler.now, action)
gate.acquire()
# There is no guarantee that the event-loop thread ends before the
# test thread is re-scheduled, give it some time to always run.
sleep(0.1)
diff = endtime - starttime
assert diff < timedelta(milliseconds=180)
assert scheduler._has_thread() is False
Expand Down
6 changes: 3 additions & 3 deletions tests/test_scheduler/test_immediatescheduler.py
Expand Up @@ -51,14 +51,14 @@ class MyScheduler(ImmediateScheduler):
def test_immediate_now(self):
scheduler = ImmediateScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) <= timedelta(milliseconds=1)

def test_immediate_now_units(self):
scheduler = ImmediateScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_immediate_scheduleaction(self):
scheduler = ImmediateScheduler()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_scheduler/test_mainloop/test_tkinterscheduler.py
Expand Up @@ -24,14 +24,14 @@ class TestTkinterScheduler(unittest.TestCase):
def test_tkinter_schedule_now(self):
scheduler = TkinterScheduler(root)
res = scheduler.now - default_now()
assert abs(res) < timedelta(milliseconds=1)
assert abs(res) <= timedelta(milliseconds=1)

def test_tkinter_schedule_now_units(self):
scheduler = TkinterScheduler(root)
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_tkinter_schedule_action(self):
scheduler = TkinterScheduler(root)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_scheduler/test_newthreadscheduler.py
Expand Up @@ -13,14 +13,14 @@ class TestNewThreadScheduler(unittest.TestCase):
def test_new_thread_now(self):
scheduler = NewThreadScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) < timedelta(milliseconds=5)

def test_new_thread_now_units(self):
scheduler = NewThreadScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_new_thread_schedule_action(self):
scheduler = NewThreadScheduler()
Expand All @@ -46,7 +46,7 @@ def action(scheduler, state):

scheduler.schedule_relative(timedelta(milliseconds=200), action)

sleep(0.3)
sleep(0.4)
assert endtime is not None
diff = endtime - starttime
assert diff > timedelta(milliseconds=180)
Expand Down Expand Up @@ -85,8 +85,8 @@ def action(state):

def test_new_thread_schedule_periodic_cancel(self):
scheduler = NewThreadScheduler()
period = 0.05
counter = 3
period = 0.1
counter = 4

def action(state):
nonlocal counter
Expand All @@ -95,6 +95,6 @@ def action(state):
return state - 1

disp = scheduler.schedule_periodic(period, action, counter)
sleep(0.10)
sleep(0.4)
disp.dispose()
assert 0 < counter < 3
assert 0 <= counter < 4
6 changes: 3 additions & 3 deletions tests/test_scheduler/test_threadpoolscheduler.py
Expand Up @@ -16,14 +16,14 @@ class TestThreadPoolScheduler(unittest.TestCase):
def test_threadpool_now(self):
scheduler = ThreadPoolScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) < timedelta(milliseconds=5)

def test_threadpool_now_units(self):
scheduler = ThreadPoolScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_schedule_action(self):
ident = threading.current_thread().ident
Expand Down
10 changes: 5 additions & 5 deletions tests/test_scheduler/test_timeoutscheduler.py
Expand Up @@ -47,14 +47,14 @@ class MyScheduler(TimeoutScheduler):
def test_timeout_now(self):
scheduler = TimeoutScheduler()
diff = scheduler.now - default_now()
assert abs(diff) < timedelta(milliseconds=1)
assert abs(diff) < timedelta(milliseconds=5)

def test_timeout_now_units(self):
scheduler = TimeoutScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_timeout_schedule_action(self):
scheduler = TimeoutScheduler()
Expand All @@ -80,7 +80,7 @@ def action(scheduler, state):

scheduler.schedule_relative(timedelta(milliseconds=200), action)

sleep(0.3)
sleep(0.4)
assert endtime is not None
diff = endtime - starttime
assert diff > timedelta(milliseconds=180)
Expand All @@ -93,7 +93,7 @@ def action(scheduler, state):
nonlocal ran
ran = True

d = scheduler.schedule_relative(timedelta(milliseconds=1), action)
d = scheduler.schedule_relative(timedelta(milliseconds=300), action)
d.dispose()

sleep(0.1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scheduler/test_trampolinescheduler.py
Expand Up @@ -18,9 +18,9 @@ def test_trampoline_now(self):
def test_trampoline_now_units(self):
scheduler = TrampolineScheduler()
diff = scheduler.now
sleep(0.1)
sleep(1.1)
diff = scheduler.now - diff
assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
assert timedelta(milliseconds=1000) < diff < timedelta(milliseconds=1300)

def test_trampoline_schedule(self):
scheduler = TrampolineScheduler()
Expand Down
4 changes: 0 additions & 4 deletions tests/test_subject/test_asyncsubject.py
Expand Up @@ -389,7 +389,3 @@ def action17(scheduler, state=None):
assert results1.messages == []
assert results2.messages == []
assert results3.messages == []


if __name__ == '__main__':
unittest.main()

0 comments on commit 39040a4

Please sign in to comment.