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

test: add tests for calc, dice plugins #2503

Closed
wants to merge 1 commit into from

Conversation

SnoopJ
Copy link
Contributor

@SnoopJ SnoopJ commented Aug 13, 2023

Description

This changeset adds tests for the calc, dice plugins, inspired by discussion on #2464.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

@dgw
Copy link
Member

dgw commented Aug 13, 2023

Is this intended to replace the tests generated by passing expected output to the @plugin.example decorator?

@plugin.command('c', 'calc')
@plugin.example('.c 5 + 3', '8')
@plugin.example('.c 0.9*10', '9')
@plugin.example('.c 10*0.9', '9')
@plugin.example('.c 2*(1+2)*3', '18')
@plugin.example('.c 2**10', '1024')
@plugin.example('.c 5 // 2', '2')
@plugin.example('.c 5 / 2', '2.5')

sopel/sopel/modules/dice.py

Lines 170 to 182 in 7b74964

@plugin.command('roll', 'dice', 'd')
@plugin.priority("medium")
@plugin.example(".roll 3d1+1", '3d1+1: (1+1+1)+1 = 4')
@plugin.example(".roll 3d1v2+1", '3d1v2+1: (1[+1+1])+1 = 2')
@plugin.example(".roll 2d4", r'2d4: \(\d\+\d\) = \d', re=True)
@plugin.example(".roll 100d1", r'[^:]*: \(100x1\) = 100', re=True)
@plugin.example(".roll 1001d1", 'I only have 1000 dice. =(')
@plugin.example(".roll 1d1 + 1d1", '1d1 + 1d1: (1) + (1) = 2')
@plugin.example(".roll 1d1+1d1", '1d1+1d1: (1)+(1) = 2')
@plugin.example(".roll 1d6 # initiative", r'1d6: \(\d\) = \d', re=True)
@plugin.example(".roll 2d20v1+2 # roll with advantage", user_help=True)
@plugin.example(".roll 2d10+3", user_help=True)
@plugin.example(".roll 1d6", user_help=True)

dice has helper functions that could be covered by unit tests, but I'm not entirely sure of the value-add here when the whole point of @example is to allow testing the expected output of commands without needing a separate test file. 🤔

@SnoopJ
Copy link
Contributor Author

SnoopJ commented Aug 13, 2023

Is this intended to replace the tests generated by passing expected output to the @plugin.example decorator?

I don't think I knew that the decorator tested the observed behavior this way! In that case, this can just be closed, it adds nothing they aren't already covering.

@SnoopJ SnoopJ closed this Aug 13, 2023
@SnoopJ SnoopJ deleted the test/calculation-plugins branch August 13, 2023 02:22
@dgw
Copy link
Member

dgw commented Aug 13, 2023

it adds nothing they aren't already covering.

It'd be cool to fill in the gaps, though. calc is at 65% and dice is at 77% coverage according to my local report.

Stuff like empty-argument branches, exception handlers, and other error conditions (including within the aforementioned helper functions) are left out, if you're looking for some test improvements you can make to these plugins. 🙂

(Up to you whether that means adding more examples and making judicious use of the user_help kwarg to @example, or covering the edge/error cases in separate test files. Or replacing the example tests with comprehensive coverage in separate test files… I was just pointing out that the minimal, "normal path" tests you had when opening this PR were redundant!)

@SnoopJ
Copy link
Contributor Author

SnoopJ commented Aug 13, 2023

Up to you whether that means adding more examples and making judicious use of the user_help kwarg to @example, or covering the edge/error cases in separate test files. Or replacing the example tests with comprehensive coverage in separate test files

I suspect more examples can get the coverage up to somewhere we're happier with. Definitely don't want to replace the examples, they're useful documentation, and splitting between examples and tests seems kind of annoying. I'll have a look-see.

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

Successfully merging this pull request may close these issues.

2 participants