bayeslite icon indicating copy to clipboard operation
bayeslite copied to clipboard

Make test_bql.py less brittle and easier to maintain

Open fsaad opened this issue 7 years ago • 0 comments

test_bql.py is over 2500 lines of tests, its purpose is to test the BQL -> SQL compiler.

The content of the tests themselves is fine, but the string comparison pattern assert bql2sql(...) == '...' is very difficult to maintain, because:

  • the string comaprison is sensitive to whitespace, which can be very difficult to debug when there is a single error,

  • python requires '' to break lines, which means we end up with tests like this:

    assert bql2sql('infer rowid, age, weight with confidence 0.9 from p1') \
        == \
        'SELECT "rowid" AS "rowid",' \
        ' "IFNULL"("age", bql_predict(1, NULL, NULL, _rowid_, 2, 0.9, NULL))' \
            ' AS "age",' \
        ' "IFNULL"("weight",'\
                ' bql_predict(1, NULL, NULL, _rowid_, 3, 0.9, NULL))' \
            ' AS "weight"' \
        ' FROM "t1";'

which is fine if the test never needs to be updated, but when the interface of bql_predict changes to have .e.g more arguments, the line becomes long and needs to be broken, leading to a very slow update process.

fsaad avatar Jun 24 '17 23:06 fsaad