-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored and added tests for backend choosing. Functionally still w…
…orks the same, but mostly rewritten.
- Loading branch information
1 parent
664bff0
commit f360492
Showing
2 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from . import BaseTests | ||
from goless import backends | ||
|
||
test_backends = dict( | ||
a=lambda: 'be_A', | ||
b=lambda: 'be_B', | ||
) | ||
|
||
|
||
class CalcBackendTests(BaseTests): | ||
def calc(self, name, testbackends=test_backends): | ||
return backends.calculate_backend(name, testbackends) | ||
|
||
def test_valid_envvar_name(self): | ||
be = self.calc('a') | ||
self.assertEqual(be, 'be_A') | ||
|
||
def test_invalid_envvar_name(self): | ||
with self.assertRaises(RuntimeError): | ||
self.calc('invalid') | ||
|
||
def test_default(self): | ||
be = self.calc('') | ||
self.assertIn(be, [v() for v in test_backends.values()]) | ||
|
||
def test_all_invalid(self): | ||
with self.assertRaises(RuntimeError): | ||
self.calc('', {}) |