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

Adiciona suporte ao Python 3.10 #15

Merged
merged 6 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: [3.7, 3.8, 3.9, 3.x]
python: [3.7, 3.8, 3.9, "3.10", 3.x]
steps:
- name: install libxml2-dev
run: sudo apt-get install libxml2-dev libxslt-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: [3.7, 3.8, 3.9, 3.x]
python: [3.7, 3.8, 3.9, "3.10", 3.x]
steps:
- name: install {libxml2,libxslt}-dev
run: sudo apt-get install libxml2-dev libxslt-dev
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ freezegun = "==0.3.10"
mypy = "==0.711"
black = "==18.9b0"
aiofiles = "==0.8.0"
uvloop = "==0.14.0"
uvloop = "==0.16.0"
sphinx = "==4.5.0"
sphinxcontrib-asyncio = "==0.3.0"
recommonmark = "==0.5.0"
orjson = "==3.4.0"
orjson = "==3.7.2"

[requires]
python_version = "3"
Expand Down
79 changes: 52 additions & 27 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs-src/compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Compatibility
~~~~~~~~~~~~~

The explicit passing of a ``loop`` keyword argument, and subsequent access of a
``.loop`` attribute, has been deprecated and will be removed in version 0.7.0 for
``.loop`` attribute, has been deprecated and was removed in version 0.7.0 for
Loggers and Handlers.

Currently tested on Python:

- 3.6
- 3.7
- 3.8
- 3.9
- 3.10
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ classifiers =
Natural Language :: English
Operating System :: MacOS :: MacOS X
Operating System :: Unix
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Software Development :: Libraries
Topic :: System :: Logging

Expand Down
12 changes: 1 addition & 11 deletions tests/handlers/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,18 @@ async def tearDown(self):
async def test_initialization(self):
mode = "x"
encoding = "utf-8"
loop = Mock()
handler = AsyncFileHandler(
filename=self.temp_file.name,
mode=mode,
encoding=encoding,
loop=loop,
filename=self.temp_file.name, mode=mode, encoding=encoding
)

self.assertIsInstance(handler, AsyncFileHandler)

self.assertEqual(handler.absolute_file_path, self.temp_file.name)
self.assertEqual(handler.mode, mode)
self.assertEqual(handler.encoding, encoding)
self.assertEqual(handler.loop, loop)

self.assertIsNone(handler.stream)

async def test_init_gets_the_running_event_loop(self):
handler = AsyncFileHandler(filename=self.temp_file.name)

self.assertIsInstance(handler.loop, asyncio.AbstractEventLoop)

async def test_close_closes_the_file(self):
handler = AsyncFileHandler(filename=self.temp_file.name)

Expand Down
13 changes: 1 addition & 12 deletions tests/handlers/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,14 @@ def test_initialization(self):
stream = Mock()
formatter = Mock()
filter = Mock()
loop = Mock()
handler = AsyncStreamHandler(
stream, level, formatter, filter, loop=loop
)
handler = AsyncStreamHandler(stream, level, formatter, filter)

self.assertIsInstance(handler, AsyncStreamHandler)

self.assertEqual(handler.level, level)
self.assertEqual(handler.formatter, formatter)
self.assertEqual(handler.stream, stream)
self.assertIn(filter, handler.filters)
self.assertEqual(handler.loop, loop)

async def test_init_gets_the_running_event_loop(self):
handler = AsyncStreamHandler(
stream=self.write_pipe, level=10, formatter=Mock()
)

self.assertIsInstance(handler.loop, asyncio.AbstractEventLoop)

async def test_init_writer_makes_pipe_nonblocking(self):
flags = fcntl.fcntl(self.write_pipe.fileno(), fcntl.F_GETFL)
Expand Down
45 changes: 1 addition & 44 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,6 @@
from tests.utils import make_read_pipe_stream_reader


class LoggerOutsideEventLoopTest(unittest.TestCase):
def test_property_loop_always_return_a_running_loop(self):
logger = Logger(name="mylogger")

# it's not safe to install the loop implictly, callers should use
# asynio.run
with self.assertRaises(RuntimeError):
logger.loop

# it's not safe to run the loop implictly, callers should use
# asynio.run
with contextlib.closing(asyncio.get_event_loop()) as loop:
with self.assertRaises(RuntimeError):
logger.loop

results = []

async def get_logger_loop():
results.append(logger.loop)

loop.run_until_complete(get_logger_loop())
logger_loop, = results

# now that the loop was explicitly set and started, we can use it
self.assertIs(logger_loop, loop)
del logger_loop
self.assertFalse(loop.is_closed())

# now that the loop was explicitly stopped, it's useless to return
loop = asyncio.get_event_loop()
with self.assertRaises(RuntimeError):
logger.loop


class LoggerTests(asynctest.TestCase):
async def setUp(self):
r_fileno, w_fileno = os.pipe()
Expand All @@ -77,7 +43,7 @@ async def test_init_with_default_handlers_initializes_handlers_for_stdout_and_st
with asynctest.patch(
"aiologger.logger.AsyncStreamHandler", side_effect=handlers
) as handler_init:
logger = Logger.with_default_handlers(loop=self.loop)
logger = Logger.with_default_handlers()
self.assertCountEqual(logger.handlers, handlers)

self.assertCountEqual(
Expand Down Expand Up @@ -399,15 +365,6 @@ async def test_it_returns_a_log_task_if_logging_is_enabled_for_level(self):
logged_content = await self.stream_reader.readline()
self.assertEqual(logged_content, b"Xablau\n")

async def test_it_only_keeps_a_reference_to_the_loop_after_the_first_log_call(
self
):
logger = Logger.with_default_handlers()
self.assertIs(logger._loop, get_running_loop())

await logger.info("Xablau")
self.assertIs(logger._loop, get_running_loop())

def test_find_caller_without_stack_info(self):
logger = Logger()

Expand Down