Giter Club home page Giter Club logo

Comments (8)

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.