Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[self-tests] test_add_option_kwargs fails on ppc64le #896

Closed
stanislavlevin opened this issue Jun 16, 2023 · 2 comments
Closed

[self-tests] test_add_option_kwargs fails on ppc64le #896

stanislavlevin opened this issue Jun 16, 2023 · 2 comments
Labels
enhancement Improvement to an already existing feature

Comments

@stanislavlevin
Copy link

test_add_option_kwargs (loguru 0.7.0) fails on ppc64le machine with:

=================================== FAILURES =================================== 
_____________________________ test_file_buffering ______________________________ 
                                                                                 
tmp_path = PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0')
                                                                                 
>   ???                                                                          
E   AssertionError: assert '' != ''                                              
E    +  where '' = <bound method Path.read_text of PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0/test.log')>()                              
E    +    where <bound method Path.read_text of PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0/test.log')> = PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0/test.log').read_text
                                                                                 
file       = PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0/test.log')
tmp_path   = PosixPath('/usr/src/tmp/pytest-of-builder/pytest-0/test_file_buffering0')
                                                                                 
tests/test_add_option_kwargs.py:30: AssertionError

According to https://docs.python.org/3/library/functions.html#open:

When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

On that machine:

(Pdb) file.stat().st_blksize
65536
(Pdb) io.DEFAULT_BUFFER_SIZE
8192
@Delgan
Copy link
Owner

Delgan commented Jun 16, 2023

Thanks for the report!

I can't remember why I wrote the test using buffering=-1.

def test_file_buffering(tmp_path):
file = tmp_path / "test.log"
logger.add(file, format="{message}", buffering=-1)
logger.debug("x" * (io.DEFAULT_BUFFER_SIZE // 2))
assert file.read_text() == ""
logger.debug("x" * (io.DEFAULT_BUFFER_SIZE * 2))
assert file.read_text() != ""

I'll update the test so that it's deterministic and not OS-dependent.

@Delgan Delgan added the enhancement Improvement to an already existing feature label Jun 16, 2023
@Delgan
Copy link
Owner

Delgan commented Jul 9, 2023

Now I remember why I implemented the test in this way. A fixed-size buffer can only be used with files opened in binary mode, but Loguru doesn't support binary mode.

The test can't be made fully deterministic, therefore I added a check to skip the test on platforms where an unexpected buffer size is encountered.

Thanks again for the report. It has been fixed on master branch.

@Delgan Delgan closed this as completed Jul 9, 2023
ncoudene pushed a commit to ncoudene/loguru that referenced this issue Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an already existing feature
Projects
None yet
Development

No branches or pull requests

2 participants