From eabed7c763c7b2c38be9899730b3ec1969cfc52c Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Sun, 20 Oct 2019 15:12:08 -0700 Subject: [PATCH] add tests for @sentinel_attribute --- tests/python/pants_test/util/test_meta.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/python/pants_test/util/test_meta.py b/tests/python/pants_test/util/test_meta.py index ada93fa34a3a..f23c0921137e 100644 --- a/tests/python/pants_test/util/test_meta.py +++ b/tests/python/pants_test/util/test_meta.py @@ -5,7 +5,8 @@ from abc import ABC, abstractmethod from dataclasses import FrozenInstanceError, dataclass -from pants.util.meta import SingletonMetaclass, classproperty, frozen_after_init, staticproperty +from pants.util.meta import (SingletonMetaclass, classproperty, frozen_after_init, + sentinel_attribute, staticproperty) from pants_test.test_base import TestBase @@ -246,6 +247,22 @@ def f(cls): self.assertEqual(Concrete2.f, 'hello') +class SentinelAttributeTest(unittest.TestCase): + + def test_sentinel_attribute(self): + @sentinel_attribute('_test_attr_name') + def f(cls): + return f.define_instance_of(cls) + + @f + class C: + pass + + self.assertEqual(f.sentinel_attribute, '_test_attr_name') + self.assertTrue(C._test_attr_name) + self.assertTrue(f.is_instance(C)) + + class FrozenAfterInitTest(unittest.TestCase): def test_no_init(self) -> None: