Edgewall Software
Modify

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#10520 closed enhancement (fixed)

[PATCH] Unit test trac.db.util.sql_escape_percent()

Reported by: Alex Willmer <alex@…> Owned by: Alex Willmer <alex@…>
Priority: low Milestone: 1.0
Component: database backend Version: 0.13dev
Severity: minor Keywords: patch
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

The file source:trunk/trac/db/tests/util.py is a little spartan, here's a shot at improving that.

Attachments (1)

test_trac.db.util.sql_escape_percent.patch (1.8 KB ) - added by Alex Willmer <alex@…> 13 years ago.

Download all attachments as: .zip

Change History (5)

by Alex Willmer <alex@…>, 13 years ago

comment:1 by Christian Boos, 13 years ago

Keywords: patch added

Good idea! However, for the specifics of sql_escape_percent, I think a doctest could be more appropriate (as it'll also serve more directly as a kind of terse "documentation" for the function).

i.e.

def sql_escape_percent(x):
    """Escapes the percent character appropriately for SQL queries.
    
    Leave it unchanged as it be substituted:
    >>> [sql_escape_percent(x) for x in ["%", "''%''", ...]]
    ["%", "''%''", ...]

    Double it so that SQL interprets it literally :
    >>> [sql_escape_percent(x) for x in ["'%'", "'''%'''", ...]]
    ["'%%'", "'''%%'''", ...]
    """

(or something like that, untested code)

Look at some other tests (e.g. source:/trunk/trac/tests/resource.py) to see how to add a DocTestSuite.

comment:2 by Remy Blank, 13 years ago

Milestone: 1.01.0-triage

Preparing for 1.0.

comment:3 by Christian Boos, 12 years ago

Milestone: next-stable-1.0.x1.0
Resolution: fixed
Status: newclosed

Patch committed in r11094.

It was not that important to have a doctest for this one (it would even have been overly verbose, given the number of tests you had).

So… Thanks!

comment:4 by Christian Boos, 12 years ago

Owner: set to Alex Willmer <alex@…>

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Alex Willmer <alex@…>.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Alex Willmer <alex@…> to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.