Skip to content

tabulate correctness tests fail when wcwidth is installed #228

Closed

Description

@Oaklight

What

Four comparisons in tabulate/test_tabulate_correctness.py fail when wcwidth is installed in the environment:

FAILED TestEdgeCases::test_unicode_basic
FAILED TestEdgeCases::test_cjk_characters
FAILED TestEdgeCases::test_mixed_cjk_ascii
FAILED TestEdgeCases::test_wide_emoji

Why

The reference tabulate computes column widths with wcwidth when that package is importable and with len(s) otherwise. Our module's default is len(s) (WIDE_CHARS_MODE is opt-in), and the test module's guarded import only shields the reference from the repo's own tabulate/ directory, not from wcwidth.

The two sides therefore apply different rules, and the tables differ:

café (e + combining acute)
  ours  "café   1"      len() = 5
  ref   "café  1"       wcwidth = 4, the combining mark is zero-width

你好
  ours  width 2         len()
  ref   width 4         wcwidth, East Asian wide = 2

Measured: wcwidth present (Python 3.10 env, pulled in as a transitive dependency) → 4 failed, 79 passed; wcwidth absent (3.12 env) → 83 passed. CI is green because the CI environment does not install wcwidth.

Fix

Hide wcwidth for the reference import — sys.modules["wcwidth"] = None makes the import fail cleanly, so the reference selects its len(s) path and both sides compute widths the same way in every environment — and add a guard test asserting tabulate.wcwidth is None, so the comparison cannot silently drift back.

This follows the same pattern as the other reference-shadowing fixes (#196 soupsieve 2.10, #205 benchmark references).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions