repo2rlenv-swe-next / tasks /swe-next-6f59fc5cd8372ff0ed91 /environment /source /tests /test_namedutils.py
Download tasks/swe-next-6f59fc5cd8372ff0ed91/environment/source/tests/test_namedutils.py from FineEnvs/repo2rlenv-swe-next: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/datasets/FineEnvs/repo2rlenv-swe-next/resolve/main/tasks/swe-next-6f59fc5cd8372ff0ed91/environment/source/tests/test_namedutils.py
- Command line
-
hf download hf://datasets/FineEnvs/repo2rlenv-swe-next/tasks/swe-next-6f59fc5cd8372ff0ed91/environment/source/tests/test_namedutils.py
-
curl -L -o test_namedutils.py https://huggingface.co/datasets/FineEnvs/repo2rlenv-swe-next/resolve/main/tasks/swe-next-6f59fc5cd8372ff0ed91/environment/source/tests/test_namedutils.py
1.47 kB
| from pickle import loads, dumps | |
| import pytest | |
| from boltons.namedutils import namedlist, namedtuple | |
| Point = namedtuple('Point', 'x, y', rename=True) | |
| MutablePoint = namedlist('MutablePoint', 'x, y', rename=True) | |
| def test_namedlist(): | |
| p = MutablePoint(x=10, y=20) | |
| assert p == [10, 20] | |
| p[0] = 11 | |
| assert p == [11, 20] | |
| p.x = 12 | |
| assert p == [12, 20] | |
| def test_namedlist_pickle(): | |
| p = MutablePoint(x=10, y=20) | |
| assert p == loads(dumps(p)) | |
| def test_namedtuple_pickle(): | |
| p = Point(x=10, y=20) | |
| assert p == loads(dumps(p)) | |
| def test_empty_field_name_raises_value_error(factory): | |
| # `all()` is True for the empty string, so an empty name used to pass both | |
| # ValueError checks and reach `name[0].isdigit()`, raising IndexError. | |
| with pytest.raises(ValueError): | |
| factory('Point', ['x', '']) | |
| def test_empty_type_name_raises_value_error(factory): | |
| with pytest.raises(ValueError): | |
| factory('', ['x', 'y']) | |
| def test_invalid_character_still_raises_value_error(factory): | |
| with pytest.raises(ValueError): | |
| factory('Point', ['x', 'y-z']) | |
| def test_valid_names_still_accepted(factory): | |
| cls = factory('Point', ['x', 'y']) | |
| assert cls(x=1, y=2).x == 1 | |