Example #1
0
def test_sshash_uses_hash_method():
    class foo(object):
        def __hash__(self):
            return 27

    f = foo()
    assert_equal(sshash(f), 27)
Example #2
0
def test_sshash_uses_hash_method():
    class foo(object):
        def __hash__(self):
            return 27

    f = foo()
    assert_equal(sshash(f), 27)
Example #3
0
def test_sshash_equal_user_defined_types_equal_results():
    class foo(object):
        def __init__(self, a):
            self.a = a
    f1 = foo(5)
    f2 = foo(5)
    assert_equal(sshash(f1), sshash(f2))
Example #4
0
def test_history():
    p = PtyProcess.spawn(
        [sys.executable,
         os.path.join(examples, "share_history.py")])
    screen = Screen(p, 80, 24)
    stream = ByteStream(screen)
    stream.start_feeding()

    try:
        assert_startswith(lambda: screen.display[0],
                          "Enter [p/q] to change mode:")
        assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (3, 1))
        p.write(b"apple\n")
        assert_startswith(lambda: screen.display[1], "p> apple")
        assert_startswith(lambda: screen.display[2], "p>")
        p.write(b"q\n")
        assert_startswith(lambda: screen.display[3], "q>")
        p.write(b"\x1bOA")  # up
        assert_startswith(lambda: screen.display[3], "p> q")
        p.write(b"\x1bOB")  # down
        assert_startswith(lambda: screen.display[3], "q>")
        p.write(b"\x1bOA")  # up
        p.write(b"\x1bOA")  # up
        assert_startswith(lambda: screen.display[3], "p> apple")
        p.sendintr()
        assert_startswith(lambda: screen.display[4], "q>")
    finally:
        p.terminate(force=True)
Example #5
0
def test_setting_dim_index(dim):
    index_attr = f"{dim}_names"
    mapping_attr = f"{dim}m"

    orig = gen_adata((5, 5))
    orig.raw = orig
    curr = orig.copy()
    view = orig[:, :]
    new_idx = pd.Index(list("abcde"), name="letters")

    setattr(curr, index_attr, new_idx)
    pd.testing.assert_index_equal(getattr(curr, index_attr), new_idx)
    pd.testing.assert_index_equal(
        getattr(curr, mapping_attr)["df"].index, new_idx)
    pd.testing.assert_index_equal(curr.obs_names, curr.raw.obs_names)

    # Testing view behaviour
    setattr(view, index_attr, new_idx)
    assert not view.is_view
    pd.testing.assert_index_equal(getattr(view, index_attr), new_idx)
    pd.testing.assert_index_equal(
        getattr(view, mapping_attr)["df"].index, new_idx)
    with pytest.raises(AssertionError):
        pd.testing.assert_index_equal(getattr(view, index_attr),
                                      getattr(orig, index_attr))
    assert_equal(view, curr, exact=True)
Example #6
0
def test_attr_deletion():
    full = gen_adata((30, 30))
    # Empty has just X, obs_names, var_names
    empty = AnnData(full.X, obs=full.obs[[]], var=full.var[[]])
    for attr in ["obs", "var", "obsm", "varm", "obsp", "varp", "layers"]:
        delattr(full, attr)
        assert_equal(getattr(full, attr), getattr(empty, attr))
    assert_equal(full, empty, exact=True)
Example #7
0
def test_sshash_equal_user_defined_types_equal_results():
    class foo(object):
        def __init__(self, a):
            self.a = a

    f1 = foo(5)
    f2 = foo(5)
    assert_equal(sshash(f1), sshash(f2))
Example #8
0
def test_sshash_returns_int():
    for o in [
            0, 1.0, 15L, "foo", (1, 2, 3), None, [1, 2, 3], {
                'a': 3,
                'b': 5
            }
    ]:
        assert_equal(type(sshash(o)), int)
Example #9
0
def test_setting_index_names_error(attr):
    orig = adata_sparse[:2, :2]
    adata = adata_sparse[:2, :2]
    assert getattr(adata, attr).name is None
    with pytest.raises(ValueError,
                       match=fr"AnnData expects \.{attr[:3]}\.index\.name"):
        setattr(adata, attr, pd.Index(["x", "y"], name=0))
    assert adata.is_view
    assert getattr(adata, attr).tolist() != ["x", "y"]
    assert getattr(adata, attr).tolist() == getattr(orig, attr).tolist()
    assert_equal(orig, adata, exact=True)
Example #10
0
def test_setting_index_names(names, after, attr):
    adata = adata_dense.copy()
    assert getattr(adata, attr).name is None
    setattr(adata, attr, names)
    assert getattr(adata, attr).name == after
    if hasattr(names, "name"):
        assert names.name is not None

    # Testing for views
    new = adata[:, :]
    assert new.is_view
    setattr(new, attr, names)
    assert_equal(new, adata, exact=True)
    assert not new.is_view
Example #11
0
def test_keybinds():
    p = PtyProcess.spawn(
        [sys.executable, os.path.join(examples, "keybinds.py")])
    screen = Screen(p, 80, 24)
    stream = ByteStream(screen)
    stream.start_feeding()

    try:
        assert_startswith(lambda: screen.display[0],
                          "Enter [p/q/r] to change mode:")
        assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (3, 1))
        p.write(b"q")
        assert_startswith(lambda: screen.display[1], "q>")
        p.write(b"r")
        assert_startswith(lambda: screen.display[1], "r>")
        p.write(b"p")
        assert_startswith(lambda: screen.display[1], "p>")
    finally:
        p.terminate(force=True)
Example #12
0
def test_startup():
    radian_command = [sys.executable, "-m", "radian"]

    with screen_process(radian_command) as (screen, process):
        assert_startswith(lambda: screen.display[0], "R ")
        assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (4, 3))
        assert_startswith(lambda: screen.display[3], "r$>")
        process.write(b"\n")
        assert_startswith(lambda: screen.display[5], "r$>")
        assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (4, 5))
        process.sendintr()
        assert_startswith(lambda: screen.display[7], "r$>")
        assert_equal(lambda: (screen.cursor.x, screen.cursor.y), (4, 7))

    with screen_process(radian_command + ["--version"]) as (screen, process):
        assert_startswith(lambda: screen.display[0], "radian version: ")
        import radian
        assert screen.display[0][16:].strip() == radian.__version__
Example #13
0
def test_sshash_equal_user_defined_types_equal_results():
    f1 = foo(5)
    f2 = foo(5)
    assert_equal(sshash(f1), sshash(f2))
Example #14
0
def test_sshash_equal_dicts_equal_results():
    a = {'a': 1, 'b': 2, 'c': 3}
    b = {'a': 1, 'b': 2, 'c': 3}
    assert_not_equal(id(a), id(b))
    assert_equal(sshash(a), sshash(b))
 def test_set_false(self):
     self.flag.set_false()
     assert_equal(False, self.flag.is_true)
 def test_contains(self):
     assert_equal(True, self.p.contains(1))
     assert_equal(True, self.p.contains(2))
     assert_equal(True, self.p.contains(3))
     assert_equal(True, self.p.contains(4))
     assert_equal(False, self.p.contains(5))
Example #17
0
def test_stats_from_sorted_readlengths():
    stats = M.stats_from_sorted_readlengths([1, 2, 3, 4])
    expected = M.Stats(nreads=4, total=10, n50=3, p95=4, esize=3.0)
    helpers.assert_equal(stats, expected)
Example #18
0
 def test_set_true(self):
     self.flag.set_true()
     assert_equal(True, self.flag.is_true)
Example #19
0
def test_sshash_returns_int():
    for o in [0, 1.0, 15L, "foo", (1,2,3), None, [1, 2, 3], {'a' : 3, 'b' : 5}]:
        assert_equal(type(sshash(o)), int )
 def test_get_all(self):
     assert_equal(self.p.get_all(), [1,2,3,4])
    def test_list(self):
        self.l.append(2, 3)
        self.l.prepend(1)

        # get
        assert_equal(self.l[0], 1)
        assert_equal(self.l[2], 3)

        # set
        self.l[0] = 0
        self.l[2] = 0
        assert_equal(self.l[0], 0)
        assert_equal(self.l[2], 0)
        self.l[0] = 1
        self.l[2] = 3

        # simple slices
        assert_equal(self.l[0:2], [1, 2])
        assert_equal(self.l[0:], [1, 2, 3])
        assert_equal(self.l[:], [1, 2, 3])
        assert_equal(self.l[:2], [1, 2])

        # get via pops
        assert_equal(self.l.lpop(), 1)
        assert_equal(self.l.rpop(), 3)
        assert_equal(self.l.lpop(), 2)
 def test_append_hashes(self):
     self.p.append_hashes([5,6,7])
     assert_equal([1,2,3,4,5,6,7], self.p.get_all())
Example #23
0
def test_sshash_equal_nparrays_equal_results():
    a = np.arange(12).reshape(3, 4)
    b = np.arange(12).reshape(3, 4)
    assert_equal(sshash(a), sshash(b))
Example #24
0
def test_sshash_equal_dicts_equal_results():
    a = {'a':1, 'b':2, 'c':3}
    b = {'a':1, 'b':2, 'c':3}
    assert_not_equal(id(a), id(b))
    assert_equal(sshash(a), sshash(b))
Example #25
0
def test_sshash_equal_nparrays_equal_results():
    a = np.arange(12).reshape(3,4)
    b = np.arange(12).reshape(3,4)
    assert_equal(sshash(a), sshash(b))
Example #26
0
def test_concatenate_with_raw():
    # dense data
    X1 = np.array([[1, 2, 3], [4, 5, 6]])
    X2 = np.array([[1, 2, 3], [4, 5, 6]])
    X3 = np.array([[1, 2, 3], [4, 5, 6]])

    X4 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])

    adata1 = AnnData(
        X1,
        dict(obs_names=["s1", "s2"], anno1=["c1", "c2"]),
        dict(var_names=["a", "b", "c"], annoA=[0, 1, 2]),
        layers=dict(Xs=X1),
    )
    adata2 = AnnData(
        X2,
        dict(obs_names=["s3", "s4"], anno1=["c3", "c4"]),
        dict(var_names=["d", "c", "b"], annoA=[0, 1, 2]),
        layers=dict(Xs=X2),
    )
    adata3 = AnnData(
        X3,
        dict(obs_names=["s1", "s2"], anno2=["d3", "d4"]),
        dict(var_names=["d", "c", "b"], annoB=[0, 1, 2]),
        layers=dict(Xs=X3),
    )

    adata4 = AnnData(
        X4,
        dict(obs_names=["s1", "s2"], anno1=["c1", "c2"]),
        dict(var_names=["a", "b", "c", "z"], annoA=[0, 1, 2, 3]),
        layers=dict(Xs=X4),
    )

    adata1.raw = adata1
    adata2.raw = adata2
    adata3.raw = adata3

    adata_all = AnnData.concatenate(adata1, adata2, adata3)
    assert isinstance(adata_all.raw, Raw)
    assert set(adata_all.raw.var_names) == {"b", "c"}
    assert_equal(adata_all.raw.to_adata().obs, adata_all.obs)
    assert np.array_equal(adata_all.raw.X, adata_all.X)

    adata_all = AnnData.concatenate(adata1, adata2, adata3, join="outer")
    assert isinstance(adata_all.raw, Raw)
    assert set(adata_all.raw.var_names) == set("abcd")
    assert_equal(adata_all.raw.to_adata().obs, adata_all.obs)
    assert np.array_equal(np.nan_to_num(adata_all.raw.X),
                          np.nan_to_num(adata_all.X))

    adata3.raw = adata4
    adata_all = AnnData.concatenate(adata1, adata2, adata3, join="outer")
    assert isinstance(adata_all.raw, Raw)
    assert set(adata_all.raw.var_names) == set("abcdz")
    assert set(adata_all.var_names) == set("abcd")
    assert not np.array_equal(np.nan_to_num(adata_all.raw.X),
                              np.nan_to_num(adata_all.X))

    del adata3.raw
    with pytest.warns(
            UserWarning,
            match=("Only some adata objects have `.raw` attribute, "
                   "not concatenating `.raw` attributes."),
    ):
        adata_all = AnnData.concatenate(adata1, adata2, adata3)
    assert adata_all.raw is None

    del adata1.raw
    del adata2.raw
    assert all(_adata.raw is None for _adata in (adata1, adata2, adata3))
    adata_all = AnnData.concatenate(adata1, adata2, adata3)
    assert adata_all.raw is None
Example #27
0
 def test_get_all(self):
     assert_equal(self.p.get_all(), [1, 2, 3, 4])
Example #28
0
 def test_set_false(self):
     self.flag.set_false()
     assert_equal(False, self.flag.is_true)
Example #29
0
 def test_remove_hashes(self):
     self.p.remove_hashes([4, 3, 2])
     assert_equal([1], self.p.get_all())
     assert_equal(True, self.p.contains(1))
     assert_equal(False, self.p.contains(2))
Example #30
0
def test_sshash_int_and_float_matches():
    assert_equal(sshash(1.), sshash(1))
    assert_equal(sshash(-1.), sshash(-1))
    assert_equal(sshash(16.), sshash(16))
    assert_equal(sshash(10000.), sshash(10000))
 def test_remove_hashes(self):
     self.p.remove_hashes([4,3,2])
     assert_equal([1], self.p.get_all())
     assert_equal(True, self.p.contains(1))
     assert_equal(False, self.p.contains(2))
Example #32
0
def test_sshash_equal_lists_equal_results():
    a = [1, 2, 3]
    b = [1, 2, 3]
    assert_not_equal(id(a), id(b))
    assert_equal(sshash(a), sshash(b))
    def test_list(self):
        self.l.append(2,3)
        self.l.prepend(1)

        # get
        assert_equal(self.l[0], 1)
        assert_equal(self.l[2], 3)

        # set
        self.l[0] = 0
        self.l[2] = 0
        assert_equal(self.l[0], 0)
        assert_equal(self.l[2], 0)
        self.l[0] = 1
        self.l[2] = 3

        # simple slices
        assert_equal(self.l[0:2], [1,2])
        assert_equal(self.l[0:], [1,2,3])
        assert_equal(self.l[:], [1,2,3])
        assert_equal(self.l[:2], [1,2])

        # get via pops
        assert_equal(self.l.lpop(), 1)
        assert_equal(self.l.rpop(), 3)
        assert_equal(self.l.lpop(), 2)
Example #34
0
def test_sshash_equal_user_defined_types_equal_results():
    f1 = foo(5)
    f2 = foo(5)
    assert_equal(sshash(f1), sshash(f2))
Example #35
0
def test_sshash_uses_hash_method():
    f = bar()
    assert_equal(sshash(f), 27)
Example #36
0
def test_sshash_uses_hash_method():
    f = bar()
    assert_equal(sshash(f), 27)
Example #37
0
def test_sshash_int_and_float_matches():
    assert_equal(sshash(1.), sshash(1))
    assert_equal(sshash(-1.), sshash(-1))
    assert_equal(sshash(16.), sshash(16))
    assert_equal(sshash(10000.), sshash(10000))
Example #38
0
 def test_append_hashes(self):
     self.p.append_hashes([5, 6, 7])
     assert_equal([1, 2, 3, 4, 5, 6, 7], self.p.get_all())
Example #39
0
def test_sshash_equal_lists_equal_results():
    a = [1, 2, 3]
    b = [1, 2, 3]
    assert_not_equal(id(a), id(b))
    assert_equal(sshash(a), sshash(b))
Example #40
0
 def test_contains(self):
     assert_equal(True, self.p.contains(1))
     assert_equal(True, self.p.contains(2))
     assert_equal(True, self.p.contains(3))
     assert_equal(True, self.p.contains(4))
     assert_equal(False, self.p.contains(5))
 def test_set_true(self):
     self.flag.set_true()
     assert_equal(True, self.flag.is_true)