From 0bd7c3d44845fa0121f0f80430f129a8627b959f Mon Sep 17 00:00:00 2001 From: Elarwei Date: Sat, 11 Jul 2026 16:29:25 +0800 Subject: [PATCH] fix(tests): ignore spurious None layer key in cellxgene repr_dict (#265) cellxgene-census now returns an AnnData whose .layers exposes a None key, which repr_dict surfaced as 'layers': [None] and broke the structural comparison in test_cellxgene_adata. repr_dict now ignores None keys, so the comparison stays on meaningful (named) elements and is robust to this upstream drift. Adds a network-free TestReprDict test that guards the behavior on every Python version (the live Census tests skip where cellxgene-census has no wheel). Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_cellxgene.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/test_cellxgene.py b/tests/test_cellxgene.py index 29b77e67d..f7413206a 100644 --- a/tests/test_cellxgene.py +++ b/tests/test_cellxgene.py @@ -34,7 +34,11 @@ def repr_dict(adata): if isinstance(got_attr, int): d[attr] = got_attr else: - keys = list(got_attr.keys()) + # Ignore None keys: some cellxgene-census versions return an AnnData + # whose `.layers` exposes a spurious `None` key, which is not a + # meaningful (named) element and would otherwise break the structural + # comparison in test_cellxgene_adata (issue #265). + keys = [k for k in got_attr.keys() if k is not None] if keys: d[attr] = keys return d @@ -96,3 +100,33 @@ def test_invalid_species_raises_valueerror(self): def test_typo_species_raises_valueerror(self): with self.assertRaises(ValueError): cellxgene(species="macaca_mulata", tissue="blood") + + +class TestReprDict(unittest.TestCase): + """Network-free tests for the repr_dict helper (issue #265). + + These do not need cellxgene-census, so they run on every Python version + (including ones where the live Census tests are skipped), guarding the + None-key handling that keeps test_cellxgene_adata robust to upstream drift. + """ + + class _FakeAnnData: + n_obs = 3 + n_vars = 2 + obs = {"cell_type": None, "tissue": None} + var = {"feature_id": None} + uns: dict = {} + obsm: dict = {} + varm: dict = {} + layers = {None: "spurious"} # cellxgene-census can expose a None-keyed layer + obsp: dict = {} + varp: dict = {} + + def test_repr_dict_ignores_none_layer_key(self): + d = repr_dict(self._FakeAnnData()) + # A layer whose only key is None must not surface as structure. + self.assertNotIn("layers", d) + # Meaningful (named) elements are still reported. + self.assertEqual(d["n_obs"], 3) + self.assertEqual(d["obs"], ["cell_type", "tissue"]) + self.assertEqual(d["var"], ["feature_id"])