Skip to content

Commit

Permalink
Merge pull request beeware#535 from freakboy3742/master
Browse files Browse the repository at this point in the history
Import antigravity
  • Loading branch information
freakboy3742 committed May 23, 2017
2 parents a08aa61 + d9b4c1c commit 6252438
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 12 deletions.
3 changes: 2 additions & 1 deletion batavia/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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')
}
13 changes: 13 additions & 0 deletions batavia/modules/_hashlib.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions compile_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def parse_args():
enabled_modules = args.modules or [
'_weakrefset',
'abc',
'antigravity',
'bisect',
'colorsys',
'copyreg',
'hashlib',
'token',
'operator',
'stat',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
46 changes: 46 additions & 0 deletions tests/modules/test_hashlib.py
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 9 additions & 7 deletions tests/modules/test_random.py
Original file line number Diff line number Diff line change
@@ -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)
""")
8 changes: 5 additions & 3 deletions tests/modules/test_webbrowser.py
Original file line number Diff line number Diff line change
@@ -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
""")

4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = {
libraryTarget: 'umd'
},
target: 'web',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
module: {
rules: [
{
Expand Down

0 comments on commit 6252438

Please sign in to comment.