marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
7.95k stars 278 forks source link

"test_has_file_and_dirname" fails with upper case __file__ #2887

Open c-w-m opened 4 days ago

c-w-m commented 4 days ago

Describe the bug

Problem: tests/_ast/test_app.py test_has_file_and_dirname fails with upper case file

>       assert glbls["file"] == __file__
E       AssertionError: assert 'd:\\code-d\\...\\test_app.py' == 'D:\\code-d\\...\\test_app.py'
E
E         - D:\code-d\ghcwm\analytic_dev\src\demo\marimo\tests\_ast\test_app.py
E         ? ^
E         + d:\code-d\ghcwm\analytic_dev\src\demo\marimo\tests\_ast\test_app.py
E         ? ^

Fix: force file.lower()

assert glbls["file"] == __file__.lower()

Environment

Windows 10

Code to reproduce

before:

    def test_has_file_and_dirname(self) -> None:
        app = App()

        @app.cell
        def f():
            file = __file__  # noqa: F841

        @app.cell
        def g():
            import marimo as mo

            dirpath = mo.notebook_dir()  # noqa: F841

        _, glbls = app.run()
        assert glbls["file"] == __file__
        assert glbls["dirpath"] == pathlib.Path(glbls["file"]).parent

after

    def test_has_file_and_dirname(self) -> None:
        app = App()

        @app.cell
        def f():
            file = __file__  # noqa: F841

        @app.cell
        def g():
            import marimo as mo

            dirpath = mo.notebook_dir()  # noqa: F841

        _, glbls = app.run()
        assert glbls["file"] == __file__.lower()
        assert glbls["dirpath"] == pathlib.Path(glbls["file"]).parent

mscolnick commented 4 days ago

hey @c-w-m thanks for pointing that out. Not sure why our windows tests don't exhibit this. Would you be open to making a PR with this fix?