Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Roy Smith
Paul Rubin wrote: > The example I quoted used an assignment expression inside a > lambda. The person who posted it, That was me. > and the person who followed it up > with the setattr alternative, both didn't notice that the assignment > expression wasn't valid Python

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Paul Rubin
Duncan Booth <[EMAIL PROTECTED]> writes: > An assignment expression, if such a thing existed wouldn't help here. > > The point being that the expression must be evaluated inside the exception > handler in assertRaises, so you either need to delay the evaluation with a > lambda, or by passing the

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Duncan Booth
Duncan Booth wrote: > An assignment expression, if such a thing existed wouldn't help here. Although of course it would help if still inside a lambda. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Duncan Booth
Paul Rubin wrote: > Peter Hansen <[EMAIL PROTECTED]> writes: >> > You want something like >> > self.assertRaises(AttributeError, lambda: self.combat.value = 1) >> >> Or, combining the two responses and avoiding the lambda: >> >> self.assertRaises(AttributeError, setattr, self.combat, 'value',

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Paul Moore
Peter Hansen <[EMAIL PROTECTED]> writes: > Roy Smith wrote: >> You want something like >> self.assertRaises(AttributeError, lambda: self.combat.value = 1) > > Or, combining the two responses and avoiding the lambda: > > self.assertRaises(AttributeError, setattr, self.combat, 'value', 1) > > Hmm..

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Paul Rubin
Peter Hansen <[EMAIL PROTECTED]> writes: > > You want something like > > self.assertRaises(AttributeError, lambda: self.combat.value = 1) > > Or, combining the two responses and avoiding the lambda: > > self.assertRaises(AttributeError, setattr, self.combat, 'value', 1) > > Hmm... this might b

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Peter Hansen
Roy Smith wrote: You want something like self.assertRaises(AttributeError, lambda: self.combat.value = 1) Or, combining the two responses and avoiding the lambda: self.assertRaises(AttributeError, setattr, self.combat, 'value', 1) Hmm... this might be a case where the lambda form is actually the m

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Paul Moore <[EMAIL PROTECTED]> wrote: > I have a class with a read-only attribute, and I want to add a unit > test to ensure that it really *is* read-only. I can do this as > > def test_readonly(self): > """Value and multiplier must be readonly""" >

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Diez B. Roggisch
Paul Moore wrote: > I have a class with a read-only attribute, and I want to add a unit > test to ensure that it really *is* read-only. I can do this as > > def test_readonly(self): > """Value and multiplier must be readonly""" > try: > self.combat.value = 1 > self.fail("Value is not read onl

Unittest - testing properties (read-only attributes)

2005-02-21 Thread Paul Moore
I have a class with a read-only attribute, and I want to add a unit test to ensure that it really *is* read-only. I can do this as def test_readonly(self): """Value and multiplier must be readonly""" try: self.combat.value = 1 self.fail("Value is not rea