Results of 1 - 10 of about 16 for sentinel (0.008 sec.)
- unittest.mock --- モックオブジェクトライブラリ 12493
- unittest.mock --- モックオブジェクトライブラリ Added in version 3.3. ソースコード: Lib/unittest/mock.py unittest.mock は Python でテストを行うためのライブラリです。 テスト対象のシステムの一部をモックオブジェクトに置き換え、どのように使われた
...スコープ内にあるモジュールやクラスの属性を変更する patch() デコレータを提供します。さらに、ユニークなオブジェクトの作成には sentinel が利用できます。 Mock や MagicMock 、 patch() の利用例は quick guide を参照してください。 Mock は unittest で利用するために...戻り値はモックオブジェクトです。通常の方法で設定することもできます: >>> mock = Mock () >>> mock . return_value . attribute = sentinel . Attribute >>> mock . return_value () <Mock name='mock()()' id='...'> >>> mock . return_value . assert_called_with () ret...のバージョンで動作するはずです。 [ 3 ] 関数はクラスまで hook しますが、各 Mock インスタンス間の独立性は保たれます。 ヘルパー sentinel unittest.mock. sentinel sentinel オブジェクトはテストで必要なユニークなオブジェクトを簡単に提供します。 属性はアクセス時に... - https://man.mtool.work/python/3.14/library/unittest.mock.html
- unittest.mock --- 入門 11991
- unittest.mock --- 入門 Added in version 3.3. Mock を使う モックでメソッドにパッチを当てる 一般的な Mock の使い方の中には次のものがあります: メソッドにパッチを当てる オブジェクトに対するメソッド呼び出しを記録する システムの他の部分からメソッ
...ジェクトを受け取ります。 patch.object : >>> original = SomeClass . attribute >>> @patch . object ( SomeClass , 'attribute' , sentinel . attribute ) ... def test (): ... assert SomeClass . attribute == sentinel . attribute ... >>> test () >>> assert SomeCla...ss . attribute == original >>> @patch ( 'package.module.attribute' , sentinel . attribute ) ... def test (): ... from package.module import attribute ... assert attribute is sentinel . attribute ... >...含む) をパッチしようとする場合、 patch.object() の代わりに patch() を使用してください: >>> mock = MagicMock ( return_value = sentinel . file_handle ) >>> with patch ( 'builtins.open' , mock ): ... handle = open ( 'filename' , 'r' ) ... >>> mock . assert_ca... - https://man.mtool.work/python/3.14/library/unittest.mock-examples.html
- イテレータオブジェクト (iterator object) 11748
- イテレータオブジェクト (iterator object) Python では二種類のイテレータオブジェクトを提供しています。一つ目はシーケンスイテレータで、 __getitem__() メソッドをサポートする任意のシーケンスを取り扱います。二つ目は呼び出し可能オブジェクトと番兵
...(sentinel value) を扱い、シーケンス内の要素ごとに呼び出し可能オブジェクトを呼び出して、センチネル値が返されたときに反復処理を終了しま...lIter_Type 型の場合に真を返します。この関数は常に成功します。 PyObject * PyCallIter_New ( PyObject * callable , PyObject * sentinel ) 戻り値: 新しい参照。 次に属します: Stable ABI . 新たなイテレータを返します。最初のパラメタ callable は引数なしで呼び出せ...callable は、呼び出されるたびに次の反復処理対象オブジェクトを返さなければなりません。生成されたイテレータは、 callable が sentinel に等しい値を返すと反復処理を終了します。 range オブジェクト PyTypeObject PyRange_Type 次に属します: Stable ABI . range オブ... - https://man.mtool.work/python/3.14/c-api/iterator.html
- dataclasses --- データクラス 9305
- dataclasses --- データクラス ソースコード: Lib/dataclasses.py このモジュールは、 __init__() や __repr__() のような 特殊メソッド を生成し、ユーザー定義のクラスに自動的に追加するデコレーターや関数を提供します。このモジュールは元々、 PEP 557 で
...ist [ int ] = field ( default_factory = list ) c = C () c . mylist += [ 1 , 2 , 3 ] As shown above, the MISSING value is a sentinel object used to detect if some parameters are provided by the user. This sentinel is used because None is a valid value for...い: def is_dataclass_instance ( obj ): return is_dataclass ( obj ) and not isinstance ( obj , type ) dataclasses. MISSING A sentinel value signifying a missing default or default_factory. dataclasses. KW_ONLY A sentinel value used as a type annotation. An... - https://man.mtool.work/python/3.14/library/dataclasses.html
- プログラミング FAQ 8560
- プログラミング FAQ 一般的な質問 ブレークポイントやステップ実行ができる、ソースコードレベルのデバッガはありますか? はい。 Python 用のデバッガについては次に解説してあり、組み込みの breakpoint() 関数でそれらのデバッガに処理を移せます。 pdb モジ
...る場合に厄介なことになる場合があります。この状況では、他のオブジェクトと必ず区別できる唯一のマーカーオブジェクト( singleton sentinel object )を作ることで対策できます。例えば、 dict.pop() のように振る舞うメソッドを実装する方法を示します: _sentinel = objec...t () def pop ( self , key , default = _sentinel ): if key in self : value = self [ key ] del self [ key ] return value if default is _sentinel : raise KeyError ( key ) re... - https://man.mtool.work/python/3.14/faq/programming.html
- 開発ツール 8317
- 開発ツール この章で紹介されるモジュールはソフトウェアを書くことを支援します。たとえば、 pydoc モジュールはモジュールの内容からドキュメントを生成します。 doctest と unittest モジュールでは、自動的に実行して予想通りの出力が生成されるか確認する
...リプタやプロキシオブジェクトにパッチする MagicMock と magic method のサポート Magic Method をモックする Magic Mock ヘルパー sentinel DEFAULT call create_autospec ANY FILTER_DIR mock_open autospec を使う モックの封印 side_effect 、 return_value 、 wraps の... - https://man.mtool.work/python/3.14/library/development.html
- What's New in Python 2.2 8317
- What's New in Python 2.2 著者 : A.M. Kuchling はじめに この文書は 2002 年 10 月 14 日にリリースされた Python 2.2.2 の新機能について解説します。Python 2.2.2 は 2001 年 12 月 21 日にリリースされた Python 2.2 のバグフィックスリリースです。 Pyt
...セスに対応するクラスだけに限定できます。 イテレータの基本的な考え方は単純です。 新しい組み込み関数 iter(obj) または iter(C, sentinel) でイテレータを取得します。 iter(obj) はオブジェクト obj のイテレータを返します。 一方 iter(C, sentinel) は、呼び出し可能オ...ブジェクト C を繰り返し呼び出し、終了を示す sentinel が返されたら反復を終えるイテレータを返します。 Python のクラスでは __iter__() メソッドを定義できます。 このメソッドは、その... - https://man.mtool.work/python/3.14/whatsnew/2.2.html
- 組み込み関数 8075
- 組み込み関数 Python インタプリタには数多くの関数と型が組み込まれており、いつでも利用できます。それらをここにアルファベット順に挙げます。 組み込み関数 A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes(
...ised. バージョン 3.10 で変更: classinfo に Union 型 を指定できるようになりました。 iter ( iterable , / ) iter ( callable , sentinel , / ) iterator オブジェクトを返します。第二引数があるかどうかによって第一引数の解釈は大きく異なります。第二引数がない場合、...オブジェクトでなければなりません。第一引数がどちらのプロトコルもサポートしない場合は TypeError 例外が送出されます。第二引数 sentinel が与えられた場合、第一引数は呼び出し可能オブジェクトでなければなりません。この場合に生成されるイテレータは __next__() メソ...ッドを呼び出すごとに引数なしで callable を呼び出します; 戻り値が sentinel と等しければ、 StopIteration が送出されます。それ以外の場合は戻り値がそのまま返されます。 Iterator Types も見てください。... - https://man.mtool.work/python/3.14/builtins/functions.html
- 1. Extending Python with C or C++ 7832
- 1. Extending Python with C or C++ It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can't be done directly in Python: they can implement new built-in objec
...thods [] = { ... { "system" , spam_system , METH_VARARGS , "Execute a shell command." }, ... { NULL , NULL , 0 , NULL } /* Sentinel */ }; Note the third entry ( METH_VARARGS ). This is a flag telling the interpreter the calling convention to be used for...eywdarg_parrot , METH_VARARGS | METH_KEYWORDS , "Print a lovely skit to standard output." }, { NULL , NULL , 0 , NULL } /* sentinel */ }; static struct PyModuleDef keywdarg_module = { . m_base = PyModuleDef_HEAD_INIT , . m_name = "keywdarg" , . m_size =... - https://man.mtool.work/python/3.14/extending/extending.html
- 3. 拡張の型の定義: 雑多なトピック 7589
- 3. 拡張の型の定義: 雑多なトピック この節ではさまざまな実装可能なタイプメソッドと、それらが何をするものであるかについて、ざっと説明します。 以下は PyTypeObject の定義です。 デバッグビルド でしか使われないいくつかのメンバは省いてあります: typ
...ブジェクトからデスクリプタを取得し、その __doc__ 属性からドキュメント文字列を取得できます。 As with the tp_methods table, a sentinel entry with a name value of NULL is required. 3.3.2. 特定の型に特化した属性の管理 簡単にするため、ここでは char * 版だけを示... - https://man.mtool.work/python/3.14/extending/newtypes.html