[Scons-users] Question over test.must_contain

RW garlicbready at googlemail.com
Tue Jul 4 19:30:35 EDT 2017


it looks like test/Docbook/dependencies/xinclude/xinclude.py
is affected by the same error as well

1/1 (100.00%) /usr/bin/python3 -tt
test/Docbook/dependencies/xinclude/xinclude.py
Traceback (most recent call last):
  File "test/Docbook/dependencies/xinclude/xinclude.py", line 47, in
<module>
    test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an
included text.')
  File "/home/ric/scons-temp/scons_patched/QMTest/TestCommon.py", line 278,
in must_contain
    contains = find(file_contents, required)
  File "/home/ric/scons-temp/scons_patched/QMTest/TestCommon.py", line 275,
in find
    return o.index(l)
TypeError: a bytes-like object is required, not 'str'

Many Thanks
Richard

On 4 July 2017 at 14:12, RW <garlicbready at googlemail.com> wrote:

> sorry that should have read
> "must_contains always deals with text and not binary data which may be
> incorrect"
>
> On 4 July 2017 at 14:06, RW <garlicbready at googlemail.com> wrote:
>
>> Hi,
>> I've noticed another python3 bug / fix
>>
>> python3 runtest.py test/Docbook/basic/xinclude/xinclude.py
>>
>> 1/1 (100.00%) /usr/bin/python3 -tt test/Docbook/basic/xinclude/xi
>> nclude.py
>> Traceback (most recent call last):
>>   File "test/Docbook/basic/xinclude/xinclude.py", line 47, in <module>
>>     test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an
>> included text.')
>>   File "/home/ric/scons-temp/scons_patched/QMTest/TestCommon.py", line
>> 278, in must_contain
>>     contains = find(file_contents, required)
>>   File "/home/ric/scons-temp/scons_patched/QMTest/TestCommon.py", line
>> 275, in find
>>     return o.index(l)
>> TypeError: a bytes-like object is required, not 'str'
>>
>> There's a couple of different ways to fix this
>>
>> # Option1
>> the simplest is to just change
>>
>> ```
>> test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an
>> included text.')
>> to
>> test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an
>> included text.', mode='r')
>> ```
>>
>> which what the other tests seem to do
>>
>> # Option2
>> To maintain consistency between python versions, another possible option
>> (maybe at the same time) is to alter the
>> must_contain function within QMTest/TestCommon.py
>> However with this approach your assuming must_contains always deals with
>> binary and not text data which may be incorrect
>>
>> ```
>> import codecs
>> file_contents = codecs.latin_1_decode(file_contents)[0]
>> ```
>>
>> Would both options or just option 1 be the best way?
>>
>> Many Thanks
>> Richard
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170705/83c087c9/attachment-0001.html>


More information about the Scons-users mailing list