Comments (8)
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.
from hip.
@pquentin I was assuming that all "sync" code wouldn't exist before running the unasync
build step but additionally "non-I/O" code like URLs, config, etc would be under both ahip
and hip
. The two would be exact copies of each-other from an API perspective. It's not too painful to have the duplication of non-I/O code because we're only writing it once anyways (on the async side, "generated" into the sync side)
In my mind the directory structure would look like this:
├── ahip
│ ├── connection.py
│ ├── url.py
│ └── tests
│ ├── test_connection.py
│ └── test_url.py
└── hip # all of this is generated
├── connection.py
├── url.py
└── tests
├── test_connection.py
└── test_url.py
Then we can have an unasync
configuration like the following:
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:
- Tests are automatically packaged with our code. (May be a negative for some users that dislike tests packaged with code).
- We are guaranteed to test both the
ahip
andhip
versions of all code - API is symmetric, users don't have to think about I/O vs. non-I/O
unasync
will have to support this kind of configuration eventually, especially if we want a broader audience. What are frameworks going to need when they want to use bothahip
andhip
for their projects?
Some cons:
- Every test is x2, even if it's maybe not necessary to be?
- Larger installs, tests are a significant portion of the size of code we ship.
from hip.
Filenames can be tests_async/
-> tests_sync/
, there's no reason to have the _
prefix since they're test-cases.
I was thinking this is a good use-case for unasync.customize_build_py()
to allow for additional rewrite rules like ahip
-> hip
and async_backend
-> sync_backend
, specifically in tests/
? And then not having those rules within src/
.
from hip.
Filenames can be
tests_async/
->tests_sync/
, there's no reason to have the_
prefix since they're test-cases.
Do you mean hip/test/with_dummyserver/test_async/test_poolmanager.py
or hip/tests_async/with_dummyserver/test_poolmanager.py
? Or something else?
And yes, I plan to use customize_build_by
for this!
from hip.
If we end up putting everything under the source root we wouldn't have an issue with test_async
versus test_sync
, the test suite would just be duplicated automatically under ahip/tests/
and hip/tests/
.
My above comment was more if we decided to go with tests/
not under the source root and end up with tests/test_async
and tests/test_sync
.
from hip.
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:
├── hip
│ ├── _async
│ │ └── connection.py
│ ├── _sync # generated
│ │ └── connection.py # generated
│ └── url.py
└── test
├── test_connection.py
└── test_url.py
Under the new scheme our hierarchy would look like:
├── ahip
│ └── connection.py
├── hip
│ ├── connection.py # generated
│ └── url.py
└── test
├── _async
│ └── test_connection.py
├── _sync # generated
│ └── test_connection.py # generated
└── test_url.py
And as you mentioned the second option (tests under the source root) would look like:
├── ahip
│ ├── connection.py
│ └── tests
│ └── test_connection.py
└── hip
├── connection.py # generated
├── tests
│ ├── test_connection.py # generated
│ └── test_url.py
└── url.py
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.
from hip.
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 ./runtests.py
that knows how to automatically regenerate the source and tests, run the tests, etc., because we don't want to do that manually. And if we have that, then... what else do we need? Putting those smarts into setup.py specifically doesn't really add anything.
(Putting the smarts for building the library itself into setup.py does make sense, because that's needed to make pip install
work. But there's no pip test
, so that argument doesn't apply to the tests.)
So I think there's two reasonable options, and they're both workable, so it's really just up to our preference:
-
We could move all the tests and code into a single
ahip
package, like in Seth's comment, and generate ahip
package alongside it. That way the tests get automatically handled by the same code that handles the main package../runtests.py
will run unasync to generate thehip
package, and then invokepytest
to run the tests in both packages. -
We could move all the main project code into a single
ahip
package, but keep the tests in a separatetests/
directory../runtests.py
would run unasync to generate thehip
package and also to generate thetests_sync/
directory, and then invokepytest
to run both sets of tests with some appropriate PYTHONPATH.
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 src/
directory, if we want to simplify our directory layout a bit.
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.
from hip.
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!
from hip.
Related Issues (20)
- When should we run unasync? HOT 3
- Overall plans for the project HOT 9
- Test the Proactor event loop on Windows + Python 3.8 HOT 1
- Repo cleanup HOT 6
- More cleanups HOT 2
- Discussion: What do we call the async versions of hip.get, hip.post, etc.? HOT 24
- What should we do with urllib3's securetransport and pyopenssl support? HOT 1
- Early data support HOT 4
- Intermittent failures HOT 3
- Stop worrying about backwards-compatibility HOT 1
- support for request targets that can't be specified as URLs
- First steps towards a high-level HTTP client API
- [API design] Streaming upload API: push-style or pull-style? HOT 3
- Tracking issue: intermittent test failures
- How to handle Response bodies?
- Improve documentation UX for sync and async APIs HOT 2
- Add support for Async and Sync Iterators as Request bodies
- ahip, hip, async tests and coverage HOT 3
- PoolManager(block=True) + trio.nursery causes EmptyPoolError HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hip.