Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
fixed categorisation of flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklambourne committed May 17, 2018
1 parent 98c52e6 commit 615b4d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 7 additions & 6 deletions batavia/builtins/sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function sum(args, kwargs) {
}
let value = args[0]
// This is unique behaviour that is handled before types are resolved and added.
// Empty strings, sets resolve to zero when provided as a single argument to sum()
// Empty strings, sets resolve to zero when provided as a single argument to sum().
let resolve_to_zero_types = [types.Set, types.Str]
if (types.isinstance(value, resolve_to_zero_types)) {
if (value === '' || (types.isinstance(value, types.Set) && value.toString() === (new types.Set()).toString())) {
return new types.Int(0)
} else if (types.isinstance(value, types.Str)) {
// Reject all non-empty strings.
return new types.Int(0).__add__(value) // This will throw the correct TypeError
return new types.Int(0).__add__(value) // This will throw the correct TypeError.
}
}
// Sets need to be handled differently to other iterable types due to use of dict for data.
Expand All @@ -36,24 +36,24 @@ function sum(args, kwargs) {
return a.__add__(b)
}, new types.Int(0))
} else if (types.isinstance(value, types.Range)) {
// This doesn't work yet
// This doesn't work yet due to upstream error.
let retval = types.Int(0)
for (let i = value.start; i < value.end; i += value.step) {
retval = retval.__add__(new types.Int(value.val[i]))
}
return retval
} else if (types.isinstance(value, types.Dict)) {
// Sum of dict is sum of keys
// Sum of dict is sum of keys.
return value.keys().reduce(function(a, b) {
return a.__add__(b)
}, new types.Int(0))
} else if (types.isinstance(value, [types.Bytes, types.Bytearray])) {
// Sum of bytearray is sum of internal value
// Sum of bytearray is sum of internal value.
if (types.isinstance(value, types.Bytearray)) {
value = value.valueOf()
}
let retval = new types.Int(0)
// Sum of non-empty byte-strings is the sum of ASCII values of each byte
// Sum of non-empty byte-strings is the sum of ASCII values of each byte.
if (value.__len__() > 0) {
for (let i = 0; i < value.__len__(); i++) {
retval = retval.__add__(new types.Int(value.val[i]))
Expand All @@ -65,6 +65,7 @@ function sum(args, kwargs) {
return a.__add__(b)
}, new types.Int(0))
}

sum.__doc__ = "sum(iterable[, start]) -> value\n\nReturn the sum of an iterable of numbers (NOT strings) plus the value\nof parameter 'start' (which defaults to 0). When the iterable is\nempty, return start."

module.exports = sum
12 changes: 10 additions & 2 deletions tests/builtins/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ def test_sum_mix_floats_and_ints(self):
class BuiltinSumFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
function = "sum"

# these are implemented, but the exact exception thrown depends on the order
# that they are iterated on being the exact same in both CPython and batavia,
# which is not guaranteed. (if an unsupported string follows an int, the error
# will be different than if it followed a float)

is_flakey = [
'test_frozenset', # This works, but python dict.keys() returns non-deterministically
'test_set', # This works, but python dict.keys() returns non-deterministically.
]

not_implemented = [
'test_frozenset' # This works, but python dict.keys() returns non-deterministically
'test_range', # This has been implemented, but fails upstream on isinstance.
'test_set' # This works, but python dict.keys() returns non-deterministically
]

0 comments on commit 615b4d4

Please sign in to comment.