Add a keys() method to ContextList. #1065

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

qris commented May 15, 2013

It's useful to be able to list all the (flattened) keys of a ContextList, to help you figure out why the variable that's supposed to be there is not. A ContextList is hard to interpret in pdb without a method like this.

All tests pass on SQLite. Not yet run on MySQL due to taking >3 hours to run the test suite.

@qris qris Add a keys() method to ContextList.
It's useful to be able to list all the (flattened) keys of a
ContextList, to help you figure out why the variable that's supposed to
be there is not. A ContextList is hard to interpret in pdb without a
method like this.
0ada607

@mjtamlyn mjtamlyn commented on an outdated diff May 15, 2013

django/test/utils.py
@@ -38,6 +38,9 @@ def __eq__(self, other):
class ContextList(list):
+ def __init__(self, *args, **kwargs):
@mjtamlyn

mjtamlyn May 15, 2013

Member

This method should be added after the docstring

@mjtamlyn

mjtamlyn May 15, 2013

Member

Also, what is it doing? I would have thought this would happen automatically

@timgraham timgraham commented on an outdated diff May 30, 2013

tests/test_client_regress/tests.py
@@ -706,6 +706,22 @@ def test_inherited_context(self):
except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist')
+ def test_context_keys_method(self):
+ """It's useful to be able to list all the (flattened) keys of a
+ ContextList, to help you figure out why the variable that's supposed
+ to be there is not."""
+
+ c1 = Context()
+ c1.update({'hello': 'world', 'goodbye': 'john'})
+ c1.update({'hello': 'dolly', 'dolly': 'parton'})
+ c2 = Context()
+ c2.update({'goodbye': 'world', 'python': 'rocks'})
+ c2.update({'goodbye': 'dolly'})
+
+ l = ContextList([c1, c2])
+ self.assertEqual(set(['None', 'True', 'False', 'hello', 'goodbye',
@timgraham

timgraham May 30, 2013

Owner

I haven't looked at the code and perhaps it's obvious, but where do 'None', 'True', and 'False' come from? I wouldn't expect them to appear given the testing data.

@timgraham timgraham commented on an outdated diff May 30, 2013

tests/test_client_regress/tests.py
@@ -706,6 +706,22 @@ def test_inherited_context(self):
except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist')
+ def test_context_keys_method(self):
+ """It's useful to be able to list all the (flattened) keys of a
@timgraham

timgraham May 30, 2013

Owner

it seems to me like this sort of docstring belongs on the keys method itself and not the test

Member

akaariai commented May 31, 2013

Merged manually

akaariai closed this May 31, 2013

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