-
-
Notifications
You must be signed in to change notification settings - Fork 22
Running unasync on test files #198
Comments
Filenames can be I was thinking this is a good use-case for |
Do you mean And yes, I plan to use |
If we end up putting everything under the source root we wouldn't have an issue with My above comment was more if we decided to go with |
Something I tend to forget is that there are parts of the codebase that don't do I/O at all, like the URL handling. I think they can stay under "hip". Anyway, here's what our current hierarchy looks like:
Under the new scheme our hierarchy would look like:
And as you mentioned the second option (tests under the source root) would look like:
I guess this is better because it's a natural way to ship the tests along with the code. I'm not too happy that in both cases there's generated code alongside normal code but it's probably not a big problem in practice. |
@pquentin I was assuming that all "sync" code wouldn't exist before running the In my mind the directory structure would look like this:
Then we can have an from setuptools import setup
import unasync
setup(... unasync.customize_build_py(
rules = [
Rule(from_pattern="ahip", to_pattern="hip"),
Rule(from_pattern="ahip/tests", to_pattern="hip/tests", additional_replacements={"ahip": "hip"}
]
)) Some of the pros I can think of:
Some cons:
|
Yeah, I don't think it's worth trying to convince setuptools to do funky special stuff just for the tests. Practically speaking, for day-to-day development, we're going to have a helper script like (Putting the smarts for building the library itself into setup.py does make sense, because that's needed to make So I think there's two reasonable options, and they're both workable, so it's really just up to our preference:
The upsides of the first approach: Slightly simpler. Makes it easier for end-users to run tests, if they feel the need to do so for some reason. Gives us the option to drop the Downsides of the first approach: Folks will complain about shipping extra megabytes of tests in their docker images. (urllib3's tests, including .pyc files, are ~1 megabyte, it looks like? So the actual cost is ~2 megabytes per image.) If we're really going to be as widely used as urllib3 then this will inevitably be a common complaint. I'd be fine with either approach really. The advantages/disadvantages are pretty minor and fairly balanced. |
I'm thinking best if we go the route of tests outside the source directory as I feel that'll be the common use-case for other projects? If so I can try tackling this. |
I'd say the route of #208 seems great and is where we're headed, going to close this. Reopen if there are still unanswered questions! |
One of Hip's main goals is to support both asynchronous I/O (asyncio, trio...) and synchronous I/O. We achieve this by running unasync to generate synchronous code from asynchronous code and writing various I/O backends, which allows us to avoid any duplication between async and sync code. See #149 for more details.
We know how to test asynchronous code (see https://github.com/python-trio/hip/blob/master/test/with_dummyserver/async/test_poolmanager.py) and sync code (by using the urllib3 tests), but we don't know how to keep a single copy of the test files yet, apart from some vague plan of using unasync in tests too.
This issue is about figuring this out: I started thinking about it since we're about to modify unasync to cope with the new hip/ahip naming.
The idea is to generate synchronous tests, ship them as part of the source distribution, install that and run pytest on the installed tests. This new process won't be more annoying because we already need to install the sdist to run tests anyway.
File names
We want to transform
hip/test/with_dummyserver/$ASYNC/test_poolmanager.py
intohip/test/with_dummyserver/$SYNC/test_poolmanager.py
. pytest allows using the same file name (test_poolmanager.py
here) as long as we add__init__.py
files in the appropriate places.We need to choose the $ASYNC and $SYNC names. Since async becomes a keyword in Python 3.7, async and sync will only work if we don't need to import those test files. We don't need to import them right now but that's how the PyOpenSSL and SecureTransport tests work in urllib3, so maybe just sticking to
_async
and_sync
is more future-proof.File contents
The async test file is going to look like this after the hip/ahip rename:
And I think the sync test file should look like this:
We need two changes here:
ahip
->hip
andasync_backends
->sync_backend
. We can specify those in the setup.py file or we can hardcode that in unasync, because hip is just that special :-).The decisions we need to make:
_async
->_sync
?ahip
->hip
andasync_backend
->sync_backend
or allow specifying it?The text was updated successfully, but these errors were encountered: