Skip to content

[CI] [Core] Prevent Black from erroring while formatting test_resource_demand_scheduler.py #21313

@bveeramani

Description

@bveeramani

Ray Component

Core

What happened + What you expected to happen

I ran black python/ray/tests/test_resource_demand_scheduler.py but got the message

error: cannot format python/ray/tests/test_resource_demand_scheduler.py: INTERNA
L ERROR: Black produced different code on the second pass of the formatter.  Ple
ase report a bug on https://github.com/psf/black/issues.  This diff might be hel
pful: /var/folders/gx/t32twm6x54dftn9b2wxcbl100000gn/T/blk_ac9kaaka.log
Oh no! 💥 💔 💥
1 file failed to reformat.

I'm not sure why the error occurs, but it seems to be related to the assertions at the end of test_add_min_workers_nodes(). If we disable formatting on the assertions, we're able to format the rest of the module.

def test_add_min_workers_nodes():
    types = {
        "m2.large": {
            "resources": {
                "CPU": 2
            },
            "min_workers": 50,
            "max_workers": 100,
        },
        "m4.large": {
            "resources": {
                "CPU": 2
            },
            "min_workers": 0,
            "max_workers": 10,
        },
        "gpu": {
            "resources": {
                "GPU": 1
            },
            "min_workers": 99999,
            "max_workers": 99999,
        },
        "gpubla": {
            "resources": {
                "GPU": 1
            },
            "min_workers": 10,
            "max_workers": 0,
        },
    }
    # yapf: disable
    assert _add_min_workers_nodes([],
                                  {},
                                  types, None, None, None) == \
        ([{"CPU": 2}]*50+[{"GPU": 1}]*99999, {"m2.large": 50, "gpu": 99999},
            {"m2.large": 50, "gpu": 99999})

    assert _add_min_workers_nodes([{"CPU": 2}]*5,
                                  {"m2.large": 5},
                                  types, None, None, None) == \
        ([{"CPU": 2}]*50+[{"GPU": 1}]*99999, {"m2.large": 50, "gpu": 99999},
            {"m2.large": 45, "gpu": 99999})

    assert _add_min_workers_nodes([{"CPU": 2}]*60,
                                  {"m2.large": 60},
                                  types, None, None, None) == \
        ([{"CPU": 2}]*60+[{"GPU": 1}]*99999, {"m2.large": 60, "gpu": 99999},
            {"gpu": 99999})

    assert _add_min_workers_nodes([{
        "CPU": 2
    }] * 50 + [{
        "GPU": 1
    }] * 99999, {
        "m2.large": 50,
        "gpu": 99999
    }, types, None, None, None) == ([{
        "CPU": 2
    }] * 50 + [{
        "GPU": 1
    }] * 99999, {
        "m2.large": 50,
        "gpu": 99999
    }, {})

    assert _add_min_workers_nodes([], {}, {"gpubla": types["gpubla"]}, None,
                                  None, None) == ([], {}, {})

    types["gpubla"]["max_workers"] = 10
    assert _add_min_workers_nodes([], {}, {"gpubla": types["gpubla"]}, None,
                                  None, None) == ([{
                                      "GPU": 1
                                  }] * 10, {
                                      "gpubla": 10
                                  }, {
                                      "gpubla": 10
                                  })
    # yapf: enable

Versions / Dependencies

  • Python: 3.8.12
  • OS: macOS 11.5.2
  • Black: 21.12b0
  • Ray commit: 14ed7cfaaa8f890204619c149d4d50b5857c3cd6

Reproduction script

black python/ray/tests/test_resource_demand_scheduler.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions