Skip to content

Commit

Permalink
Merge pull request beeware#541 from kjcole/master
Browse files Browse the repository at this point in the history
Fixed "noargs" error text for ascii(), bin(), callable() and chr()
  • Loading branch information
freakboy3742 committed May 25, 2017
2 parents 2f22821 + 4e1f819 commit acb077e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion batavia/builtins/ascii.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ascii(args, kwargs) {
throw new exceptions.TypeError.$pyclass("ascii() doesn't accept keyword arguments")
}
if (!args || args.length !== 1) {
throw new exceptions.TypeError.$pyclass('ascii() takes exactly 1 argument (' + args.length + ' given)')
throw new exceptions.TypeError.$pyclass('ascii() takes exactly one argument (' + args.length + ' given)')
}

var repr_string = repr([args[0]], null)
Expand Down
9 changes: 7 additions & 2 deletions batavia/builtins/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ function bin(args, kwargs) {
throw new exceptions.TypeError.$pyclass("bin() doesn't accept keyword arguments")
}
if (!args || args.length !== 1) {
throw new exceptions.TypeError.$pyclass('bin() expected exactly 1 argument (' + args.length + ' given)')
throw new exceptions.TypeError.$pyclass('bin() takes exactly one argument (' + args.length + ' given)')
}

var obj = args[0]

if (!types.isinstance(obj, types.Int)) {
if (!types.isinstance(obj, types.Int) &&
!types.isinstance(obj, types.Bool)) {
throw new exceptions.TypeError.$pyclass(
"'" + type_name(obj) + "' object cannot be interpreted as an integer")
}

if (types.isinstance(obj, types.Bool)) {
return new types.Str('0b' + obj.__int__().toString(2))
}

return new types.Str('0b' + obj.toString(2))
}
bin.__doc__ = 'bin(number) -> string\n\nReturn the binary representation of an integer.\n\n '
Expand Down
2 changes: 1 addition & 1 deletion batavia/builtins/callable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function callable(args, kwargs) {
throw new exceptions.TypeError.$pyclass("callable() doesn't accept keyword arguments")
}
if (!args || args.length !== 1) {
throw new exceptions.TypeError.$pyclass('callable() expected exactly 1 argument (' + args.length + ' given)')
throw new exceptions.TypeError.$pyclass('callable() takes exactly one argument (' + args.length + ' given)')
}
if ((args[0] instanceof Function) || (args[0] instanceof types.Function)) {
return new types.Bool(true)
Expand Down
14 changes: 13 additions & 1 deletion batavia/builtins/chr.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var constants = require('../core').constants
var exceptions = require('../core').exceptions
var types = require('../types')

Expand All @@ -9,7 +10,18 @@ function chr(args, kwargs) {
throw new exceptions.TypeError.$pyclass('chr() takes no keyword arguments')
}
if (!args || args.length !== 1) {
throw new exceptions.TypeError.$pyclass('chr() takes exactly 1 argument (' + args.length + ' given)')
switch (constants.BATAVIA_MAGIC) {
case constants.BATAVIA_MAGIC_34:
throw new exceptions.TypeError.$pyclass('chr() takes exactly 1 argument (' + args.length + ' given)')

case constants.BATAVIA_MAGIC_35a0:
case constants.BATAVIA_MAGIC_35:
case constants.BATAVIA_MAGIC_353:
throw new exceptions.TypeError.$pyclass('chr() takes exactly one argument (' + args.length + ' given)')

default:
throw new exceptions.BataviaError.$pyclass('Unsupported BATAVIA_MAGIC. Possibly using unsupported Python version (supported: 3.4, 3.5)')
}
}
return new types.Str(String.fromCharCode(args[0]))
// After tests pass, let's try saving one object creation
Expand Down
1 change: 0 additions & 1 deletion tests/builtins/test_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class BuiltinAsciiFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
functions = ["ascii"]

not_implemented = [
'test_noargs',
'test_class',
'test_NotImplemented',
]
2 changes: 0 additions & 2 deletions tests/builtins/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ class BuiltinBinFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
functions = ["bin"]

not_implemented = [
'test_noargs',
'test_bool',
'test_int',
]
1 change: 0 additions & 1 deletion tests/builtins/test_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ class BuiltinCallableFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
functions = ["callable"]

not_implemented = [
'test_noargs',
'test_class',
]

0 comments on commit acb077e

Please sign in to comment.