Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for translator.py #40

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

dhruvagarwal
Copy link
Contributor

  • add tests for process_arguments
  • add tests for take_body

These two methods cover a big part of the module. Right now, the test coverage is 77%.

@@ -277,6 +281,232 @@ def test_parse_raw_request_no_path(self):
with self.assertRaises(ValueError):
translator.parse_raw_request(raw_request)

def test_process_arguments_with_no_arguments(self):
# Arguments
args = argparse.Namespace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what I was trying to avoid. Using a hardcoded Namespace means that we'll have to update this in sync with any changes to made to the parser defined in take_arguments. This also prevents testing of the parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this can be avoided by making a function over it, and passing only the required attributes.
Everything else, would be set to None. Then the updation part will be bypassed.
We can write separate tests for parser(which is what principle of unit testing says)
What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I get what you mean. Can you please just code the function you're talking about. 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying, a function like namespace_loader(**kwargs) to which you provide something like

data="sample data",
request="GET HTTP/1.1 Host: www.google.com".
so, the namespace loader returns you an object with the kwargs provided. rest everything can be set to a default value, which is None here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Yes! That'll surely simplify the code a bit, but still, keeping all this separate from the actual parser feels a bit odd to me, tbh. :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to check through the complete process, is it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! The parser and the process_arguments functions are too tightly coupled, IMO and testing them separately is a bit weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would completely agree with you on that point. but still the tests shouldn't depend on them, and my aim was to just lay down some cases. Putting some utility functions like namespace_loader should make these tests independent of the way anything's written. Moreover, as far as your reason is concerned to make it go through the parser. the namespace_loader can be written in such a way that it goes through the parser as well. Modularizing the things will definitely help.

import argparse


def load_args(**kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dufferzafar I was talking about something like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this definitely improves the code!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and does it help in solving the problem you stated ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in its current state, no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm. ok can you describe, what are you expecting ideally ?

@DePierre
Copy link
Contributor

@dhruvagarwal Is this ready to review? Or should I wait until the second item in your list is checked?

@dhruvagarwal
Copy link
Contributor Author

@DePierre yes, this is ready for review. I'll add the tests for take_body in another pull

search_regex=None,
search_string=None
)
for key, value in kwargs.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not python3 compliant.

@DePierre
Copy link
Contributor

DePierre commented Apr 6, 2016

@dhruvagarwal Do you think that is it important to test for other languages as well? I see that you used bash for the unit tests. Would it be interesting to use the other supported languages as well?

@DePierre
Copy link
Contributor

@dhruvagarwal Are you still concerned by your PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants