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

Create new unit tests for Evennia #1458

Open
Griatch opened this issue Oct 1, 2017 · 19 comments
Open

Create new unit tests for Evennia #1458

Griatch opened this issue Oct 1, 2017 · 19 comments
Labels
good first issue Low hanging fruit for those wanting to help out. Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ help wanted We specifically want more help on this one. task A bigger, more general work plan for a bigger issue.

Comments

@Griatch
Copy link
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% 64% 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.

@Griatch Griatch added Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ task A bigger, more general work plan for a bigger issue. master-branch labels Oct 1, 2017
@vaibhavsingh97
Copy link

i can give it a try 😄

@Keda87
Copy link

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
Copy link
Member Author

Griatch commented Oct 2, 2017

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

@Griatch
Copy link
Member Author

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
Copy link

Keda87 commented Oct 2, 2017

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

@Griatch
Copy link
Member Author

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
Copy link

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
Copy link

Keda87 commented Oct 4, 2017

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

@Griatch
Copy link
Member Author

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
Copy link

@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
Copy link
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
Copy link
Contributor

vonzimr commented Oct 6, 2017

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

@Griatch
Copy link
Member Author

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.

@WanderCreate
Copy link

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
Copy link
Member Author

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 Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Nov 5, 2017
@Griatch Griatch changed the title Create new unit tests for Evennia - hacktoberfest Create new unit tests for Evennia Nov 5, 2017
@Griatch Griatch added the help wanted We specifically want more help on this one. label Feb 4, 2018
@Griatch Griatch added the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Sep 25, 2018
@Griatch Griatch removed the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Nov 5, 2018
@Griatch Griatch added this to To do in Evennia 1.0 Sep 9, 2019
@Griatch Griatch added the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Oct 1, 2019
@Griatch Griatch removed the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Oct 31, 2019
@Griatch Griatch added the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Oct 1, 2020
@Griatch Griatch removed the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Nov 1, 2020
@Griatch Griatch added the Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ label Oct 1, 2021
@Griatch Griatch removed this from To do in Evennia 1.0 Jan 19, 2022
@Griatch Griatch moved this from In progress to Finished in PyPi milestone Feb 5, 2022
@selberhad
Copy link
Contributor

selberhad commented Oct 3, 2022

@Griatch There seems to be an issue with the coveralls configuration. I can't view any of the source files to see where the coverage gaps are. The error is of the form:

SOURCE NOT AVAILABLE
The file "/home/runner/work/evennia/evennia/evennia/contrib/tutorial_world/objects.py" isn't available on github. Either it's been removed, or the repo root directory needs to be updated.

Unless I'm doing something wrong, it's been a few years since I last used coveralls.

@selberhad
Copy link
Contributor

I looked into the error message and it appears that repo owners should be given an option to change the repo root directory when that error message pops up. HTH!

@Griatch
Copy link
Member Author

Griatch commented Oct 3, 2022

@selberhad Oh, haven't looked at the detailed coverage in the while. I updated the root now, so you should be able to see the source code. Thanks for the heads up!

(The develop branch coverage on coveralls.io is also weird. If you run locally, the coverage for that branch is 66%, but on coveralls.io it reports 26% for develop branch. It just dropped some months ago. Not sure what's going on there ☹️ )

@Griatch
Copy link
Member Author

Griatch commented Oct 22, 2022

Turns out that coverage doesn't like parallel execution. The coverage data was fixed now, so develop branch shows the correct percentage (66%): https://coveralls.io/github/evennia/evennia?branch=develop 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Low hanging fruit for those wanting to help out. Hacktoberfest Help out in October and win prizes! https://hacktoberfest.digitalocean.com/ help wanted We specifically want more help on this one. task A bigger, more general work plan for a bigger issue.
Projects
No open projects
PyPi milestone
  
Finished
Development

No branches or pull requests

7 participants