我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用fileinput.isstdin()。
def isstdin(self): self.invocation_counts["isstdin"] += 1 return self.return_values["isstdin"]
def test_state_is_None(self): """Tests fileinput.isstdin() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._state""" fileinput._state = None with self.assertRaises(RuntimeError) as cm: fileinput.isstdin() self.assertEqual(("no active input()",), cm.exception.args) self.assertIsNone(fileinput._state)
def test_state_is_not_None(self): """Tests fileinput.isstdin() when fileinput._state is not None. Ensure that it invokes fileinput._state.isstdin() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.""" isstdin_retval = object() instance = MockFileInput() instance.return_values["isstdin"] = isstdin_retval fileinput._state = instance retval = fileinput.isstdin() self.assertExactlyOneInvocation(instance, "isstdin") self.assertIs(retval, isstdin_retval) self.assertIs(fileinput._state, instance)