|
| 1 | +# |
| 2 | +# Copyright 2025 Two Sigma Open Source, LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +import pickle |
| 18 | +import unittest |
| 19 | + |
| 20 | +from uberjob._transformations.caching import BarrierType, Barrier |
| 21 | +from uberjob._util import MissingType, Missing, OmittedType, Omitted |
| 22 | +from uberjob._util.traceback import TruncatedStackFrameType, TruncatedStackFrame |
| 23 | + |
| 24 | +ATOMS = [ |
| 25 | + (BarrierType, Barrier, "Barrier"), |
| 26 | + (MissingType, Missing, "Missing"), |
| 27 | + (OmittedType, Omitted, "<...>"), |
| 28 | + (TruncatedStackFrameType, TruncatedStackFrame, "TruncatedStackFrame"), |
| 29 | +] |
| 30 | + |
| 31 | + |
| 32 | +class AtomTestCase(unittest.TestCase): |
| 33 | + def test_atom_singleton(self): |
| 34 | + for atom_type, atom, _ in ATOMS: |
| 35 | + with self.subTest(atom_type_name=atom_type.__name__): |
| 36 | + self.assertIs(atom_type(), atom_type()) |
| 37 | + self.assertIs(atom_type(), atom) |
| 38 | + |
| 39 | + def test_atom_pickle_round_trip_is_atom(self): |
| 40 | + for atom_type, atom, _ in ATOMS: |
| 41 | + with self.subTest(atom_type_name=atom_type.__name__): |
| 42 | + self.assertIs(pickle.loads(pickle.dumps(atom)), atom) |
| 43 | + |
| 44 | + def test_type_of_atom_is_atom_type(self): |
| 45 | + for atom_type, atom, _ in ATOMS: |
| 46 | + with self.subTest(atom_type_name=atom_type.__name__): |
| 47 | + self.assertIs(type(atom), atom_type) |
| 48 | + |
| 49 | + def test_atom_repr(self): |
| 50 | + for atom_type, atom, atom_repr in ATOMS: |
| 51 | + with self.subTest(atom_type_name=atom_type.__name__): |
| 52 | + self.assertEqual(repr(atom), atom_repr) |
0 commit comments