[Tutor] unittests, testing a type
davea at ieee.org
Fri Jul 17 02:47:26 CEST 2009
Todd Matsumoto wrote:
> Thanks for all the comments so far.
> DaveA, I'm receiving the value via pyODBC, after running a query on a database. The test is to first make sure the value is a Decimal (pyODBC returns a Decimal object if what is coming from the database is a decimal type). So if I don't have a value that is a Decimal object something is wrong.
> -------- Original-Nachricht --------
>> Datum: Tue, 14 Jul 2009 22:36:14 -0400
>> Von: Dave Angel <davea at ieee.org>
>> CC: Todd Matsumoto <tmatsumoto at gmx.net>, tutor at python.org
>> Betreff: Re: Re: [Tutor] unittests, testing a type
>> On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto<tmatsumoto at gmx.net> wrote:
>>>> The reason why is I'm receiving the Decimal value from another program,
>> if I already know that the value will be a Decimal why test it?
>> How are you receiving it? File, pickle, pipe, socket, exit() return
>> value? When I first read your question, I assumed you meant "from
>> another module." But if it's another process, then you'd better tell us
>> how you're actually getting the value. Maybe it's a Decimal because you
>> just got done converting it to one.
If the value is being passed back from another module, and you therefore
want to do an exact test on the type, just do
if type(a) == decimal.Decimal:
On the other hand, if you just want to know if it's a particular type,
or some subclass of that type, use isinstance();.
More information about the Tutor