Comments (8)
I'm also having quite a bit of trouble understanding the magic in the unit tests to figure out what it's actually testing there.
from jsonschema.
Well. The fact that I can't answer you immediately as to why the validation is being done there suggests that refactoring is needed. Whether what you're suggesting is feasible or not we can see. I do trust that I'd have put it there for some reason, but I'd need to look at it more carefully to see what that might be, or whether it still applies.
That being said – for it to be wrong, there needs to be a failing test (an example with incorrect behavior). If you have one, please provide it. Otherwise, it may be confusingly written (I'd certainly agree there :) but it's at least correct and conforming as far as the tests say – which, last I checked, cover the spec as well as I could interpret it. (Heh, now that I see that there's at least one JSON Schema committee member lurking around I have to be careful about being disparaging about the spec without feeling the need to help out with it, but hey, that's what drafts are for I guess).
If you feel that your refactoring better represents the desired behavior though (and as presented, I'd definitely agree from a cursory look), feel free to do it. If the tests still pass afterwards, you know what you did was good, and if they don't maybe they'll indicate a reason for the current implementation.
I can apologize for the way the unit tests are written, there was a need for parametrized tests here and I basically through a quick parametrized test case together. The magic that goes on essentially just turns each of the tuples you see there into individual test cases, and, based on whether it's supposed to be "valid"
or "invalid"
, performs the corresponding test. If that still confuses you, I can elaborate.
from jsonschema.
Yeah, I think the tests aren't failing because the schemas that are being tested are not correctly using the dependencies property. I figured out the testing framework magic, and made a pull request with tests and code updated to how I understand the spec, see if it makes sense to you.
from jsonschema.
To elaborate, I think this is how you would write a schema using the dependencies property to require that 'bar' be at least 3 when 'foo' is defined:
{
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "integer"}
},
"dependencies": {
"foo": {
"properties": {
"bar": {
"minimum": 3
}
}
}
}
}
Note that the dependencies property is used at the root of the schema rather than in the 'foo' subschema.
EDIT: Here is an example which seems to support my theory: https://groups.google.com/d/msg/json-schema/TujXnT3-K_M/0a3Q2-zPccQJ
from jsonschema.
Yup, definitely looks like you're right, thanks!
I rebased, since as committed it broke the build (on Python 3). If you just forgot (or didn't have a Py3 around) that's totally fine, but just in case you didn't catch the note in the readme, running tox
should have shown you the failure.
from jsonschema.
Sorry about that, yeah I was just running the tests on 2.6. I'll make sure to run the tests properly in the future. :)
from jsonschema.
No worries. I just like to make sure every commit works, so, if you want to do what I do, you can just commit away each time, only running the tests on one version while you work, and then right before you push, run tox
(on each commit if you want to be fancy and overcareful), make sure it works, and if not, rebase and fix then push.
from jsonschema.
Alrighty, I'm set up with 2.6, 2.7 and 3.2. Tox can't find my pypy interpreter on windows for some reason though. I'll at least make sure any future contributions are good on those.
from jsonschema.
Related Issues (20)
- Support encountering of a `"deprecated": true` keyword by propagating a deprecation warning HOT 7
- Bug: checking required fields doesn't produce error when not present. HOT 2
- Failed to validate the schema when shifted from RefResolver to Registry HOT 4
- ModuleNotFoundError: No module named 'rpds.rpds' HOT 6
- PyO3 error HOT 5
- Draft07Valiadator doesn't validate dates HOT 1
- Inconsistent behaviour of validator_for depending on http vs https HOT 2
- Validation starting from sub-definition
- Getting schema contents after refs are resolved HOT 1
- `format: uri` doesn't work properly HOT 4
- Issue with oneOf validation HOT 6
- Unable to resolve a realtive `$ref` from a schema with `$id` pointed to a subschema in `$defs` with `$id` HOT 2
- Self referenced schema encapsulation breaks reference resolution HOT 1
- jsonschema.TypeChecker with additional types fails to work after several reference resolutions by the referencing.Registry HOT 2
- validate fails to identify incorrect uuid strings HOT 3
- 'Tuple' arrays not handled correctly HOT 3
- validate() throwing exception for a valid schema HOT 1
- Draft7Validator(TyperError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry' HOT 2
- Which is the last version not requiring Rust via its dependencies?
- Migrating From RefResolver, unable to resolve $ref
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 jsonschema.