Tone Analyzer: Add support for JSON and HTML input to tone() method#218
Tone Analyzer: Add support for JSON and HTML input to tone() method#218germanattanasio merged 6 commits intowatson-developer-cloud:masterfrom jeffpk62:master
Conversation
|
Not sure what travis/python 2.7 doesn't like about the return statements for the tone() method? I tried to use a ternarary in the request, but that wasn't working, so I took the simple approach of using one of two requests depending on the content type. |
|
@jeffpk62 We are autogenerating this file from the swagger. If the generation isn't working as expected it's probably because the swagger doesn't have the I think @glennrfisher can autogenerate this fix once we fix the swagger. However, I think the examples are good and we should keep them. |
|
@germanattanasio I saw a reference to auto-generation, but the code had also been changed manually. At some point, it appeared that the content-type support was removed, along with a few other changes? So I'm not sure what's happening, but one way or another, we really need to enable this functionality. I'm trying to document the SDK, and it looks pretty bad if the SDK drops features. Perhaps until we determine why the auto-generation isn't doing the right thing, we can include this change? The examples I added won't work without the code changes. |
|
Unfortunately, I'm busy and won't have a chance to review your changes until next week. For what it's worth, here is a commit where I replaced the generated It would be good to add support for multiple content-types, but it might be tricky to do so without a breaking change. For example, on a quick skim of your code, I noticed that the So before merging any changes, we should make sure that they could not break any existing code. That means it must have the same parameter order, and must send the exact same request when |
|
@glennrfisher, yep, I should move it to the end. Sorry, I forgot about the optional parameter specification for the positional arguments. All of the existing tests passed, but they all specify the parameter names. I'll submit a fix for that. Other than that, it should not break existing functionality. One of the reasons there are some odd content-type checks in the code is to ensure that we do the same thing (default to plain text) if the parameter is omitted; otherwise, the code could have been simpler. I'll submit an update for the order issue, but it's a rather small change. I'd like to have the SDK work the same as the service before releasing a slew of pending updates to the API reference. So if there's any chance you could get to a quick review sooner, that would help me out a lot. Thanks. |
Codecov Report
@@ Coverage Diff @@
## master #218 +/- ##
==========================================
- Coverage 84.23% 81.49% -2.75%
==========================================
Files 24 24
Lines 1161 1167 +6
==========================================
- Hits 978 951 -27
- Misses 183 216 +33
Continue to review full report at Codecov.
|
|
Fixed placement of content_type parameter and added/updated tests to check for positional correctness. |
|
@jeffpk62 you have a Check the line 71 in |
|
Hey, @germanattanasio, yeah I saw that on the initial build. The code is set up that way because it can make the request in one of two ways depending on the content type. If it's application/json, we make the request with the first set of parameters; otherwise, we make the request with the second set of parameters. Other than trying some kind of ternary operator on the request, which seemed odd in Python, this seemed like the best way to make the request depending on the content type. I need to do something like this to support the different input options and to maintain backward compatibility. Do you have any ideas on how to rework this? Should I mess with the ternary operator again? Thanks! |
|
Probably better if you write 2 tests even if you will be duplicating code. It's better to have multiple smaller tests |
|
That would be fine if these were in the test cases, @germanattanasio . But this is what I needed to do to accommodate the different content types for the tone() method in the main Tone Analyzer module. I could write a second version of the tone() method, but that just didn't seem like a good idea. |
|
@germanattanasio, I used two if clauses instead of an if/else, and that appears to have gotten past the lint checker. But Python 3.3 is giving me an Assertion error because it reverses the order of the parameters on one of the test calls to the service. All other versions are fine, and py.test passes with my local Python 2.7.13. If I reverse the expected order of the parameters to get past this error with Python 3.3, tests fail for other versions of Python, including my local version. I could remove the assertion from the code, but that seems wrong. Do you have any idea why this might be happening? |
|
@germanattanasio, this is ready for review and hopefully merging. Thanks for the workaround for the nondeterministic parameter assertion. |
Adds the missing content types, JSON and HTML. Also preserves the functionality of the existing code for backward-compatibility. Adds a number of new examples to demonstrate the new content types. See issue #217.