[Zope3-checkins] CVS: Zope3/src/zope/app/rdb/tests - test_zopecursor.py:1.5

Marius Gedminas mgedmin@centras.lt
Fri, 4 Jul 2003 17:13:25 +0300


--98e8jtXdkpgskNou
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jul 04, 2003 at 09:52:34AM -0400, Sidnei da Silva wrote:
> Update of /cvs-repository/Zope3/src/zope/app/rdb/tests
> In directory cvs.zope.org:/tmp/cvs-serv6843/tests
>=20
> Modified Files:
> 	test_zopecursor.py=20
> Log Message:
> Now its really fixed. Fetchone returns 'None' when there are no more resu=
lts, according to the docstring
>=20
> =3D=3D=3D Zope3/src/zope/app/rdb/tests/test_zopecursor.py 1.4 =3D> 1.5 =
=3D=3D=3D
> --- Zope3/src/zope/app/rdb/tests/test_zopecursor.py:1.4	Fri Jul  4 09:33:=
38 2003
> +++ Zope3/src/zope/app/rdb/tests/test_zopecursor.py	Fri Jul  4 09:52:30 2=
003
> @@ -38,16 +38,18 @@
> =20
>  class MyCursorStub(CursorStub):
> =20
> +    _raw =3D raw
> +
>      description =3D ((None, 'string'), (None, 'int'), (None, 'foo'))
> =20
>      def fetchone(self):
> -        return raw[:1][0]
> +        return self._raw[:1][0]

That's equivalent to just

           return self._raw[0]

but I'd write

           if self._raw:
               return self._raw[0]
           else:
               return None

to handle empty result sets

> @@ -86,6 +88,14 @@
>      def test_cursor_fetchone(self):
>          results =3D self.cursor.fetchone()
>          expected =3D converted[:1][0]

That's also equivalent to

           expected =3D converted[0]

I don't remember if 'converted' can ever be []

> +        self.assertEqual(results, expected,
> +                   'type conversion was not performed in cursor.fetchone=
:\n'
> +                   'got %r, expected %r' % (results, expected))
> +
> +    def test_cursor_fetchone_no_more_results(self):
> +        self.cursor._raw[0] =3D None

That's a bit ugly.  I'd prefer

           self.cursor._raw =3D []

provided that MyCursorStub.fetchone handles that as illustrated above.

> +        results =3D self.cursor.fetchone()
> +        expected =3D None
>          self.assertEqual(results, expected,
>                     'type conversion was not performed in cursor.fetchone=
:\n'
>                     'got %r, expected %r' % (results, expected))

HTH,
Marius Gedminas
--=20
Codeworks is available for Zope consulting -- http://www.codeworks.lt/

--98e8jtXdkpgskNou
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/BYuFkVdEXeem148RAgLUAJ9kclBZySLjyEah7VE7mJXjjZfl0QCghrrx
KEjBhSl/adG/MnRR09yIzKQ=
=BD57
-----END PGP SIGNATURE-----

--98e8jtXdkpgskNou--