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

Create new unit tests for Evennia #1458

Open
Griatch opened this Issue Oct 1, 2017 · 15 comments

Comments

6 participants
@Griatch
Member

Griatch commented Oct 1, 2017

Brief summary of issue / Description of requested feature:

This is an issue originally started under hacktoberfest but extended beyond that. The issue is for expanding Evennia's unit test coverage. This is also a great way to learn some of Evennia's systems under the hood.

Steps to reproduce the issue / Reasons for adding feature:

  1. Go to the coveralls page for Evennia
  2. Find an Evennia module under evennia/ that lacks unit test coverage.
    a. Exception: /evennia/game_template/* is not much point to unit test
    b. Exception: Any /migrations sub directories should not have unit tests
  3. If you are new to Evennia, please see the Getting Started instructions on how to set up Evennia locally - you can just create an empty game folder.
  4. See Evennia's How to unit test Evennia page for more info. Tests of this issue will run by executing evennia test evennia from the game dir.
  5. If no tests.pyfile yet exists in the sub-package in question, add it and then add your test to it. It will automatically be picked up by the test runner. See other tests.py in the Evennia repo for help.
  6. Here is help on django unit testing should you need it.
  7. If you are unsure about how GIT/PRs etc work, check out the Forking Evennia page.

Expected result of feature

We are currently at 53% unit test coverage, why not expand that?

Extra information, such as Evennia revision/repo/branch, operating system and ideas for how to solve / implement:

This is against master branch. Ask in forum or chat (#evennia on irc.freenode.net) if you have any questions on how to test a particular system - we are happy to help!


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@vaibhavsingh97

This comment has been minimized.

Show comment
Hide comment
@vaibhavsingh97

vaibhavsingh97 Oct 1, 2017

i can give it a try 😄

vaibhavsingh97 commented Oct 1, 2017

i can give it a try 😄

@Keda87

This comment has been minimized.

Show comment
Hide comment
@Keda87

Keda87 Oct 2, 2017

Hi, just find out this repo for hacktoberfest.
I'll try to add some test tonight, do you have any convention/documentation to create test and PR?

Keda87 commented Oct 2, 2017

Hi, just find out this repo for hacktoberfest.
I'll try to add some test tonight, do you have any convention/documentation to create test and PR?

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 2, 2017

Member

@Keda87, @vaibhavsingh97 That's great! I updated the issue with some more info. :)

Member

Griatch commented Oct 2, 2017

@Keda87, @vaibhavsingh97 That's great! I updated the issue with some more info. :)

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 2, 2017

Member

I also added some exceptions. No need to dig into making unit tests for the game_template since it's basically well, empty template files.

Member

Griatch commented Oct 2, 2017

I also added some exceptions. No need to dig into making unit tests for the game_template since it's basically well, empty template files.

@Keda87

This comment has been minimized.

Show comment
Hide comment
@Keda87

Keda87 Oct 2, 2017

@Griatch how can I see coverage report for testing on my local machine?

Keda87 commented Oct 2, 2017

@Griatch how can I see coverage report for testing on my local machine?

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 2, 2017

Member

@Keda87 It's not necessary to run coverage locally for this issue. But if you want to try it you need to follow these steps:

  1. In your virtualenv, do pip install coverage
  2. Assuming you installed Evennia according to the Getting Started instructions you should have your evennia/ folder sitting next to your game dir (called e.g. mygame/). cd into your game dir.
  3. Run one of the following:
# linux 
coverage run --source=../evennia --omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service ../evennia/bin/unix/evennia test evennia

# windows (untested)
coverage run --source=../evennia --omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service ../evennia/bin/windows/evennia test evennia
  1. Let the tests run to completion. Then run coverage report. You will get a list of all files and the full unit test coverage of the entire Evennia package (currently 53%). You can also do coverage report path/to/python/file.py to see coverage of only that file.
Member

Griatch commented Oct 2, 2017

@Keda87 It's not necessary to run coverage locally for this issue. But if you want to try it you need to follow these steps:

  1. In your virtualenv, do pip install coverage
  2. Assuming you installed Evennia according to the Getting Started instructions you should have your evennia/ folder sitting next to your game dir (called e.g. mygame/). cd into your game dir.
  3. Run one of the following:
# linux 
coverage run --source=../evennia --omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service ../evennia/bin/unix/evennia test evennia

# windows (untested)
coverage run --source=../evennia --omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service ../evennia/bin/windows/evennia test evennia
  1. Let the tests run to completion. Then run coverage report. You will get a list of all files and the full unit test coverage of the entire Evennia package (currently 53%). You can also do coverage report path/to/python/file.py to see coverage of only that file.
@gulasnani

This comment has been minimized.

Show comment
Hide comment
@gulasnani

gulasnani Oct 4, 2017

@Griatch Hi, I read some documentation and have started with some testing on syscommands.py, but I am not able to follow how the args passed on to cmdobj in each test are used. Could you direct me to the particular docs that may make me understand how the strings passed in the tests as args are handled by CommandTest?

Spare me for a noobish question but am new to gitHub :p
Thanks!

gulasnani commented Oct 4, 2017

@Griatch Hi, I read some documentation and have started with some testing on syscommands.py, but I am not able to follow how the args passed on to cmdobj in each test are used. Could you direct me to the particular docs that may make me understand how the strings passed in the tests as args are handled by CommandTest?

Spare me for a noobish question but am new to gitHub :p
Thanks!

@Keda87

This comment has been minimized.

Show comment
Hide comment
@Keda87

Keda87 Oct 4, 2017

@Griatch thank you, I just want to ensure the coverage increasing

Keda87 commented Oct 4, 2017

@Griatch thank you, I just want to ensure the coverage increasing

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 4, 2017

Member

@gulasnani As you can see in TestCommand, the args you pass in is stored on the command object here https://github.com/evennia/evennia/blob/master/evennia/commands/default/tests.py#L64.

Normally (when a real command is run in Evennia), these are the arguments passed to the command. So if the command was look here (defined by the CmdLook class in another module) then args would be the string " here".

Now, in the case of the test, the execution of the command is emulated, with the body of the command being executed when first the .parse and then the .func method fires here: https://github.com/evennia/evennia/blob/master/evennia/commands/default/tests.py#L76 (in a live Evennia, this sequence is called by the cmdhandler system). As .parse and then .func runs, the developer creating a Command has access to all properties assigned to the Command instance earlier, including that .args. How .parse and .func are implemented is up to the developer and what kind of command is desired. In the example of look here, it would try to figure out what "here" means and try to display its description.

In the specific case of the syscommands.py module, those commands are standard examples of various fallback commands to run when no specific one has been found. So they often don't do much by default. But here is an example of one of them picking up the .args and operating on it: https://github.com/evennia/evennia/blob/master/evennia/commands/default/syscommands.py#L149

Hope that helps!

Member

Griatch commented Oct 4, 2017

@gulasnani As you can see in TestCommand, the args you pass in is stored on the command object here https://github.com/evennia/evennia/blob/master/evennia/commands/default/tests.py#L64.

Normally (when a real command is run in Evennia), these are the arguments passed to the command. So if the command was look here (defined by the CmdLook class in another module) then args would be the string " here".

Now, in the case of the test, the execution of the command is emulated, with the body of the command being executed when first the .parse and then the .func method fires here: https://github.com/evennia/evennia/blob/master/evennia/commands/default/tests.py#L76 (in a live Evennia, this sequence is called by the cmdhandler system). As .parse and then .func runs, the developer creating a Command has access to all properties assigned to the Command instance earlier, including that .args. How .parse and .func are implemented is up to the developer and what kind of command is desired. In the example of look here, it would try to figure out what "here" means and try to display its description.

In the specific case of the syscommands.py module, those commands are standard examples of various fallback commands to run when no specific one has been found. So they often don't do much by default. But here is an example of one of them picking up the .args and operating on it: https://github.com/evennia/evennia/blob/master/evennia/commands/default/syscommands.py#L149

Hope that helps!

@gulasnani

This comment has been minimized.

Show comment
Hide comment
@gulasnani

gulasnani Oct 5, 2017

@Griatch Thanks a lot for walking me through! Quite helpful it was, as there were just a few bits I overlooked which were of actual importance for the overall understanding.

gulasnani commented Oct 5, 2017

@Griatch Thanks a lot for walking me through! Quite helpful it was, as there were just a few bits I overlooked which were of actual importance for the overall understanding.

@vonzimr

This comment has been minimized.

Show comment
Hide comment
@vonzimr

vonzimr Oct 6, 2017

Contributor

Is there a nice way to run only specific tests? I see that I can run
evennia test evennia
or
evennia test [component]

But if I just wanted to test, say, the accounts module how would I go about that?

Contributor

vonzimr commented Oct 6, 2017

Is there a nice way to run only specific tests? I see that I can run
evennia test evennia
or
evennia test [component]

But if I just wanted to test, say, the accounts module how would I go about that?

@vonzimr

This comment has been minimized.

Show comment
Hide comment
@vonzimr

vonzimr Oct 6, 2017

Contributor

Reading the django docs, I found writing
evennia test evennia.[module name]
seems to work!

Contributor

vonzimr commented Oct 6, 2017

Reading the django docs, I found writing
evennia test evennia.[module name]
seems to work!

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 6, 2017

Member

Yes evennia test enennia.accounts will work. To get to a specific test in a tests.py module you could also specify down to class or even class method level; like evennia test evennia.accounts.tests.TestStuff.test_particular_thing.

Member

Griatch commented Oct 6, 2017

Yes evennia test enennia.accounts will work. To get to a specific test in a tests.py module you could also specify down to class or even class method level; like evennia test evennia.accounts.tests.TestStuff.test_particular_thing.

@BeaData

This comment has been minimized.

Show comment
Hide comment
@BeaData

BeaData Oct 12, 2017

Hi, I'd like to help too by running some tests :)
Currently setting up Evennia; I'll work on Windows 10 by the way, any particular issues you may want me to focus on? Let me know!

BeaData commented Oct 12, 2017

Hi, I'd like to help too by running some tests :)
Currently setting up Evennia; I'll work on Windows 10 by the way, any particular issues you may want me to focus on? Let me know!

@Griatch

This comment has been minimized.

Show comment
Hide comment
@Griatch

Griatch Oct 12, 2017

Member

@BeaData Any tests are good tests. See the first post of this issue, they should help to get you going. Pick an untested module/package that looks interesting to you. :)

Member

Griatch commented Oct 12, 2017

@BeaData Any tests are good tests. See the first post of this issue, they should help to get you going. Pick an untested module/package that looks interesting to you. :)

@Griatch Griatch removed the Hacktoberfest label Nov 5, 2017

@Griatch Griatch changed the title from Create new unit tests for Evennia - hacktoberfest to Create new unit tests for Evennia Nov 5, 2017

@Griatch Griatch added the help wanted label Feb 4, 2018

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