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

Import antigravity #535

Merged
merged 5 commits into from May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion batavia/modules.js
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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
Expand Up @@ -13,6 +13,10 @@ module.exports = {
libraryTarget: 'umd'
},
target: 'web',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
module: {
rules: [
{
Expand Down