divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00126
[Merge] lp:~divmod-dev/divmod.org/831895-assertThrows-varargs into lp:divmod.org
Jonathan Jacobs has proposed merging lp:~divmod-dev/divmod.org/831895-assertThrows-varargs into lp:divmod.org.
Requested reviews:
Divmod-dev (divmod-dev)
Related bugs:
Bug #831895 in nevow: "Allow assertThrows to pass varargs to callable, like assertRaises"
https://bugs.launchpad.net/nevow/+bug/831895
For more details, see:
https://code.launchpad.net/~divmod-dev/divmod.org/831895-assertThrows-varargs/+merge/72547
--
https://code.launchpad.net/~divmod-dev/divmod.org/831895-assertThrows-varargs/+merge/72547
Your team Divmod-dev is requested to review the proposed merge of lp:~divmod-dev/divmod.org/831895-assertThrows-varargs into lp:divmod.org.
=== modified file 'Nevow/nevow/js/Divmod/Test/TestUnitTest.js'
--- Nevow/nevow/js/Divmod/Test/TestUnitTest.js 2008-02-26 07:18:22 +0000
+++ Nevow/nevow/js/Divmod/Test/TestUnitTest.js 2011-08-23 11:04:24 +0000
@@ -123,6 +123,33 @@
/**
+ * L{assertThrows} passes additional varargs to C{callable}.
+ */
+ function test_assertThrowsVarargs(self) {
+ var args = [];
+ function foo(a, b, c) {
+ args.push(a);
+ args.push(b);
+ args.push(c);
+ throw Divmod.UnitTest.AssertionError();
+ }
+
+ var expectedArgs = [1, 'two', [3, 3, 3]];
+ try {
+ self.assertThrows(
+ Divmod.UnitTest.AssertionError,
+ foo,
+ expectedArgs[0],
+ expectedArgs[1],
+ expectedArgs[2]);
+ } catch (e) {
+ self.fail("assertThrows should have passed: " + e.message);
+ }
+ self.assertArraysEqual(args, expectedArgs);
+ },
+
+
+ /**
* Test that L{compare} does not raise an exception if its callable
* returns C{true}.
*/
=== modified file 'Nevow/nevow/js/Divmod/UnitTest.js'
--- Nevow/nevow/js/Divmod/UnitTest.js 2008-12-31 18:44:01 +0000
+++ Nevow/nevow/js/Divmod/UnitTest.js 2011-08-23 11:04:24 +0000
@@ -406,8 +406,9 @@
* @param expectedError: The error type (class or prototype) which is
* expected to be thrown.
*
- * @param callable: A no-argument callable which is expected to throw
- * C{expectedError}.
+ * @param callable: A callable which is expected to throw C{expectedError}.
+ *
+ * @param ...: Optional positional arguments passed to C{callable}.
*
* @throw AssertionError: Thrown if the callable doesn't throw
* C{expectedError}. This could be because it threw a different error or
@@ -415,10 +416,11 @@
*
* @return: The exception that was raised by callable.
*/
- function assertThrows(self, expectedError, callable) {
+ function assertThrows(self, expectedError, callable /*... */) {
var threw = null;
+ var args = Array.prototype.slice.call(arguments, 3);
try {
- callable();
+ callable.apply(null, args);
} catch (e) {
threw = e;
self.assert(e instanceof expectedError,
Follow ups