diff --git a/batavia/modules.js b/batavia/modules.js index 3e2e6fe0b..495742373 100644 --- a/batavia/modules.js +++ b/batavia/modules.js @@ -5,6 +5,7 @@ module.exports = { '_compile': require('./modules/_compile/_compile'), + '_hashlib': require('./modules/_hashlib'), '_operator': require('./modules/_operator'), '_weakref': require('./modules/_weakref'), 'base64': require('./modules/base64'), @@ -15,6 +16,6 @@ module.exports = { 'math': require('./modules/math'), 'sys': require('./modules/sys'), 'time': require('./modules/time'), - 'random': require('./modules/random') + 'random': require('./modules/random'), 'webbrowser': require('./modules/webbrowser') } diff --git a/batavia/modules/_hashlib.js b/batavia/modules/_hashlib.js new file mode 100644 index 000000000..db902cde3 --- /dev/null +++ b/batavia/modules/_hashlib.js @@ -0,0 +1,13 @@ +var hashlib = { + '__doc__': '', + '__file__': 'batavia/modules/hashlib.js', + '__name__': 'hashlib', + '__package__': '' +} + +// hashlib.choice = function(choices) { +// var index = Math.floor(Math.hashlib() * choices.length) +// return choices[index] +// } + +module.exports = hashlib diff --git a/compile_stdlib.py b/compile_stdlib.py index e8fe3eab3..6670fd0af 100644 --- a/compile_stdlib.py +++ b/compile_stdlib.py @@ -27,9 +27,11 @@ def parse_args(): enabled_modules = args.modules or [ '_weakrefset', 'abc', + 'antigravity', 'bisect', 'colorsys', 'copyreg', + 'hashlib', 'token', 'operator', 'stat', diff --git a/package.json b/package.json index 7655fa061..439af55b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pybee/batavia", - "version": "3.4.0-dev.18", + "version": "3.4.0-dev.19", "description": "A Javascript implementation of the Python virtual machine.", "main": "batavia/batavia.js", "directories": { diff --git a/tests/modules/test_hashlib.py b/tests/modules/test_hashlib.py new file mode 100644 index 000000000..75a49a971 --- /dev/null +++ b/tests/modules/test_hashlib.py @@ -0,0 +1,46 @@ +import unittest + +from ..utils import TranspileTestCase + + +class HashlibTests: + @unittest.expectedFailure + def test_digest(self): + self.assertCodeExecution(""" + import hashlib + m = hashlib.%s() + m.update(b"Nobody inspects") + m.update(b" the spammish repetition") + print(m.digest()) + """ % self.ALGORITHM) + + @unittest.expectedFailure + def test_hexdigest(self): + self.assertCodeExecution(""" + import hashlib + print(hashlib.%s(b"Nobody inspects the spammish repetition").hexdigest()) + """ % self.ALGORITHM) + + +class MD5Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'md5' + + +class SHA1Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'sha1' + + +class SHA224Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'sha224' + + +class SHA256Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'sha256' + + +class SHA384Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'sha384' + + +class SHA512Tests(TranspileTestCase, HashlibTests): + ALGORITHM = 'sha512' diff --git a/tests/modules/test_random.py b/tests/modules/test_random.py index 7c9c7c8bb..5b9154337 100644 --- a/tests/modules/test_random.py +++ b/tests/modules/test_random.py @@ -1,10 +1,12 @@ -import unittest +from ..utils import TranspileTestCase -import random - -class RandomTests(unittest.TestCase): +class RandomTests(TranspileTestCase): def test_choice(self): - numbers = [1, 2, 3, 4, 5, 6, 7, 8] - random_number = random.choice(numbers) - self.assertIn(random_number, numbers) + self.assertCodeExecution(""" + import random + + numbers = [1, 2, 3, 4, 5, 6, 7, 8] + random_number = random.choice(numbers) + self.assertIn(random_number, numbers) + """) diff --git a/tests/modules/test_webbrowser.py b/tests/modules/test_webbrowser.py index aa715d4fd..40ece5b91 100644 --- a/tests/modules/test_webbrowser.py +++ b/tests/modules/test_webbrowser.py @@ -1,6 +1,8 @@ -from ..utils import ModuleFunctionTestCase, TranspileTestCase +from ..utils import TranspileTestCase -class Base64Tests(ModuleFunctionTestCase, TranspileTestCase): +class WebbrowserTests(TranspileTestCase): def test_import(self): - self.assertCodeExecution("import webbrowser") + self.assertCodeExecution(""" + import webbrowser + """) diff --git a/webpack.config.js b/webpack.config.js index c671602ec..154532416 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,10 @@ module.exports = { libraryTarget: 'umd' }, target: 'web', + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new webpack.NoEmitOnErrorsPlugin() + ], module: { rules: [ {