[issue15826] Increased test coverage of test_glob.py

2012-08-30 Thread Alessandro Moura

New submission from Alessandro Moura:

Hi,

Here is a patch to increase test coverage of test_glob.py. I added tests where 
the glob patterns are of type bytes. The coverage (according to coverage.py) is 
now complete, except for what are clearly artefacts probably caused by the fact 
that glob is loaded before coverage measurements start (global statements are 
reported not covered but local ones are).

--
components: Tests
files: glob-cov-incr.patch
keywords: patch
messages: 169496
nosy: eng793
priority: normal
severity: normal
status: open
title: Increased test coverage of test_glob.py
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file27067/glob-cov-incr.patch

___
Python tracker 
<http://bugs.python.org/issue15826>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15826] Increased test coverage of test_glob.py

2012-08-31 Thread Alessandro Moura

Alessandro Moura added the comment:

Agreed, here is the patch where this is done.

--
Added file: http://bugs.python.org/file27078/test_glob.patch

___
Python tracker 
<http://bugs.python.org/issue15826>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15837] Added test to test_random.py testing Random.shuffle

2012-08-31 Thread Alessandro Moura

New submission from Alessandro Moura:

Random.shuffle does not have a test in test_random.py; the attached patch adds 
this test. In addition, I rewrote the documentation string for Random.shuffle, 
which apparently did not reflect recent changes in the code and was 
inconsistent with the definition of the method. This change is also part of 
this patch; I was not sure if this merited a separate issue, so I just included 
this here.

On a related matter: in Random.shuffle there is a third optional argument which 
looks very odd to me:

def shuffle(self, x, random=None, int=int):


Besides being confusing to a user typing help(shuffle), what the "int" argument 
does in shuffle is to convert a float to an integer. But one could pass any 
one-argument function in principle, and it would be then very hard to predict 
what shuffle would do... it would not "shuffle" any more in the traditional 
sense - not with a uniform probability distribution. In summary, I don't see 
how that argument could be useful, although the people who wrote the library 
must have had something in mind... if so it would be a good idea to document it.

--
components: Tests
messages: 169603
nosy: eng793
priority: normal
severity: normal
status: open
title: Added test to test_random.py testing Random.shuffle
type: enhancement
versions: Python 3.3

___
Python tracker 
<http://bugs.python.org/issue15837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15837] Added test to test_random.py testing Random.shuffle

2012-09-01 Thread Alessandro Moura

Alessandro Moura added the comment:

Sorry, here it is the patch.

--
keywords: +patch
Added file: http://bugs.python.org/file27082/random.patch

___
Python tracker 
<http://bugs.python.org/issue15837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15826] Increased test coverage of test_glob.py

2012-09-01 Thread Alessandro Moura

Alessandro Moura added the comment:

test_bytes_glob_directory_with_trailing_slash already has a counterpart in the 
main class, but it is not easily handled by overriding self.glob and self.norm. 
Since it is only a single test, I just decided to override 
test_glob_directory_with_trailing_slash from the main class. But looking at 
this now I realize that I actually created another method with a different name 
by mistake; so the attached patch changes that.

--
Added file: http://bugs.python.org/file27083/test_glob.patch

___
Python tracker 
<http://bugs.python.org/issue15826>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15826] Increased test coverage of test_glob.py

2012-09-01 Thread Alessandro Moura

Alessandro Moura added the comment:

Im OK with the patch changes.

'''
/home/rdmurray/python/p33/Lib/os.py:263: BytesWarning: Comparison between bytes 
and string
  if tail == curdir:   # xxx/newdir/. exists if xxx/newdir exists
/home/rdmurray/python/p33/Lib/glob.py:63: BytesWarning: Comparison between 
bytes and string
  if basename == '':
'''

Yes, I do see these warnings running with -b. I will look into them and try to 
fix them.

--

___
Python tracker 
<http://bugs.python.org/issue15826>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15845] Fixing some byte-to-string conversion warnings

2012-09-01 Thread Alessandro Moura

New submission from Alessandro Moura:

This is related to issue 15826.

When run with the -b option, some glob.py and os.py functions give warnings due 
to byte-to-string conversions:


amoura@amoura-laptop:~/cpython$ ./python -b -c "import glob; 
glob.glob(b'cover*/glob.cover')"
/home/amoura/cpython/Lib/glob.py:64: BytesWarning: Comparison between bytes and 
string
  if basename == '':
amoura@amoura-laptop:~/cpython$ ./python -b -c "import os; 
os.makedirs(b'tst/making/dirs')"
/home/amoura/cpython/Lib/os.py:266: BytesWarning: Comparison between bytes and 
string
  if tail == cdir:   # xxx/newdir/. exists if xxx/newdir exists

The attached patch fixes this.

There is a rather more mysterious phenomenon with exceptions (which is 
triggered by test_exceptions for ImportException, but it happens for any 
Exception class):

>>> e = Exception(b'aaa')
[60596 refs]
>>> e.args[0]
b'aaa'
[60601 refs]
>>> str(e)
__main__:1: BytesWarning: str() on a bytes instance
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs]
>>> str(e)
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs]

In other words, if a bytes argument is given to the exception, the first call 
to str triggers the warning, but further calls don't. Is this worth pursuing?

--
components: Library (Lib)
files: os_glob_bytes.patch
keywords: patch
messages: 169683
nosy: eng793
priority: normal
severity: normal
status: open
title: Fixing some byte-to-string conversion warnings
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file27092/os_glob_bytes.patch

___
Python tracker 
<http://bugs.python.org/issue15845>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15841] Some StringIO and BytesIO methods can succeed after close

2012-09-02 Thread Alessandro Moura

Alessandro Moura added the comment:

This also happens for the writable() and seekable() methods. The problem is 
that those methods do not check whether the buffers have been closed in 
stringio.c. This is fixed in the attached patch for StringIO. BytesIO should be 
the same, but bytesio.c is structured differently, and I still have to 
understand the code. I will try to do this, and then add tests for this issue - 
which should go in one of the mixins of test_memoryio.py, I presume.

--
keywords: +patch
nosy: +eng793
Added file: http://bugs.python.org/file27094/stringio.c.patch

___
Python tracker 
<http://bugs.python.org/issue15841>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15841] Some StringIO and BytesIO methods can succeed after close

2012-09-02 Thread Alessandro Moura

Alessandro Moura added the comment:

Here is the patch fixing the issue in both StringIO and BytesIO. In both cases, 
the problem is that in their respective c files, these methods always returned 
true, without testing whether the file was closed. Is this a recent rewrite? I 
am surprised this did not bite someone earlier.

I also added a testcase to test_memoryio.py covering this issue; and I added 
the docstring for these methods, which were missing.

This patch compiles and passes the entire test suite in my system.

--
Added file: http://bugs.python.org/file27096/memio.patch

___
Python tracker 
<http://bugs.python.org/issue15841>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15841] Some StringIO and BytesIO methods can succeed after close

2012-09-02 Thread Alessandro Moura

Alessandro Moura added the comment:

Sorry, I should have seen the related issue (or just read the docs :)).

Here is the patch fixing these issues, implementing the behaviour stated in the 
docs (raising ValueError after close). The tests revealed that the _pyio module 
also needed fixing, and this is done in the patch as well.

--
Added file: http://bugs.python.org/file27102/memoryio.patch

___
Python tracker 
<http://bugs.python.org/issue15841>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15837] Added test to test_random.py testing Random.shuffle

2012-09-03 Thread Alessandro Moura

Alessandro Moura added the comment:

Comparing the execution time with and without the int=int argument of this 
command:

amoura@amoura-laptop:~/cpython$ time ./python -c "from random import shuffle; 
lst=list(range(100)); shuffle(lst); print (len(lst))"

I get with int=int:

real0m13.755s
user0m13.777s
sys 0m0.124s

and without it:

real0m13.876s
user0m13.701s
sys 0m0.116s

So it makes no difference in practice. On the other hand, removing this has a 
chance of braking existing code, if someone somewhere actually uses the third 
argument for something - I can't image what, but still...

--

___
Python tracker 
<http://bugs.python.org/issue15837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15837] Added test to test_random.py testing Random.shuffle

2012-09-03 Thread Alessandro Moura

Alessandro Moura added the comment:

The int=int still makes no difference, but if the second argument is set to 
random.random, we get a big speedup, regardless of whether the third argument 
is there:

without int=int:

amoura@amoura-laptop:~/cpython$ time ./python -c "import random; 
lst=list(range(100)); random.shuffle(lst,random.random); print (len(lst))"
100

real0m7.082s
user0m6.952s
sys 0m0.116s

With int=int:

amoura@amoura-laptop:~/cpython$ time ./python -c "import random; 
lst=list(range(100)); random.shuffle(lst,random.random); print (len(lst))"
100

real0m7.281s
user0m7.156s
sys 0m0.100s

Without second argument:

amoura@amoura-laptop:~/cpython$ time ./python -c "import random; 
lst=list(range(100)); random.shuffle(lst); print (len(lst))"
100

real0m13.783s
user0m13.609s
sys 0m0.108s

This could be because of the many tests of whether the 2nd argument is None in 
the loop.

--

___
Python tracker 
<http://bugs.python.org/issue15837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15837] Added test to test_random.py testing Random.shuffle

2012-09-03 Thread Alessandro Moura

Alessandro Moura added the comment:

Yup. This is the result of simply eliminating the condition in the loop and 
just using the second argument (for the purposes of testing this only):


amoura@amoura-laptop:~/cpython$ time ./python -c "import random; 
lst=list(range(100)); random.shuffle(lst,random.random); print (len(lst))"
100

real0m7.330s
user0m7.148s
sys 0m0.092s

--

___
Python tracker 
<http://bugs.python.org/issue15837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15841] Some StringIO and BytesIO methods can succeed after close

2012-09-04 Thread Alessandro Moura

Alessandro Moura added the comment:

Thanks. Here is the amended patch with your suggestions implemented.

--
Added file: http://bugs.python.org/file27117/memoryio.patch

___
Python tracker 
<http://bugs.python.org/issue15841>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15841] Some StringIO and BytesIO methods can succeed after close

2012-09-05 Thread Alessandro Moura

Alessandro Moura added the comment:

I just emailed my contributor's agreement.

--

___
Python tracker 
<http://bugs.python.org/issue15841>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15842] Some SocketIO methods can succeed after close()

2012-09-05 Thread Alessandro Moura

Alessandro Moura added the comment:

This patch fixes the problem, making those methods raise a ValueError exception 
after close.

I also added one test case for this issue.

--
keywords: +patch
nosy: +eng793
Added file: http://bugs.python.org/file27128/socket.patch

___
Python tracker 
<http://bugs.python.org/issue15842>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15872] shutil.rmtree(..., ignore_errors=True) doesn't ignore all errors

2012-09-06 Thread Alessandro Moura

Alessandro Moura added the comment:

Yes, confirmed. When checking whether the provided path is a directory, rmtree 
does not check whether ignore_errors is set. According to the docstring, "If 
ignore_errors is set, errors are ignored". Presumably this means any error, in 
which case this is not the desired behaviour.

The attached patch fixes this.

--
keywords: +patch
nosy: +eng793
Added file: http://bugs.python.org/file27138/shutil.patch

___
Python tracker 
<http://bugs.python.org/issue15872>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15872] shutil.rmtree(..., ignore_errors=True) doesn't ignore all errors

2012-09-06 Thread Alessandro Moura

Alessandro Moura added the comment:

Added test to patch.

--
Added file: http://bugs.python.org/file27139/shutil.patch

___
Python tracker 
<http://bugs.python.org/issue15872>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15842] Some SocketIO methods can succeed after close()

2012-09-08 Thread Alessandro Moura

Alessandro Moura added the comment:

Fixed seekable(), and amended tests; see patch.

--
Added file: http://bugs.python.org/file27149/socket.patch

___
Python tracker 
<http://bugs.python.org/issue15842>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com