from pytest import mark
from itertools import chain, product
from scell.core import select, Monitored


def test_select(handles):
    assert select([], []) == ([], [])
    assert select(handles, []) == (handles, [])
    assert select(handles, handles) == (handles, handles)


def test_monitored(handle, mode):
    monitor = Monitored(handle, mode)
    assert monitor.mode == mode
    assert not monitor.callback()


@mark.parametrize(
    'fmode,ok',
    [
        ('r', [(1, 0), (1, 1)]),
        ('w', [(0, 1), (1, 1)]),
        ('rw', [(1, 1)]),
    ]
)
def test_monitored_ready(handle, fmode, ok):
    monitor = Monitored(handle, fmode)
    for r, w in product((0,1), repeat=2):
        monitor.readable = r
        monitor.writable = w

        if (r, w) in ok:
            assert monitor.ready
            continue

        assert not monitor.ready

@@ -427,21 +427,16 @@
 metrize(
-%0A    
 'fmode,o
@@ -442,19 +442,11 @@
 ok',
-%0A    %5B%0A    
+ %5B%0A
     
@@ -466,28 +466,24 @@
 , (1, 1)%5D),%0A
-    
     ('w', %5B(
@@ -503,20 +503,16 @@
 %5D),%0A    
-   
- 
 ('rw', %5B
@@ -525,14 +525,9 @@
 %5D),%0A
-    %5D%0A
+%5D
 )%0Ade

make decorator more dense