|
@@ -1,4 +1,4 @@
|
|
-from typing import Set
|
|
|
|
|
|
+from typing import List, Set
|
|
|
|
|
|
import pytest
|
|
import pytest
|
|
|
|
|
|
@@ -8,51 +8,55 @@ from pynecone.var import ImportVar
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
@pytest.mark.parametrize(
|
|
- "lib,fields,output",
|
|
|
|
|
|
+ "fields,test_default,test_rest",
|
|
[
|
|
[
|
|
(
|
|
(
|
|
- "axios",
|
|
|
|
{ImportVar(tag="axios", is_default=True)},
|
|
{ImportVar(tag="axios", is_default=True)},
|
|
- 'import axios from "axios"',
|
|
|
|
|
|
+ "axios",
|
|
|
|
+ set(),
|
|
),
|
|
),
|
|
(
|
|
(
|
|
- "axios",
|
|
|
|
{ImportVar(tag="foo"), ImportVar(tag="bar")},
|
|
{ImportVar(tag="foo"), ImportVar(tag="bar")},
|
|
- 'import {bar, foo} from "axios"',
|
|
|
|
|
|
+ "",
|
|
|
|
+ {"foo", "bar"},
|
|
),
|
|
),
|
|
(
|
|
(
|
|
- "axios",
|
|
|
|
{
|
|
{
|
|
ImportVar(tag="axios", is_default=True),
|
|
ImportVar(tag="axios", is_default=True),
|
|
ImportVar(tag="foo"),
|
|
ImportVar(tag="foo"),
|
|
ImportVar(tag="bar"),
|
|
ImportVar(tag="bar"),
|
|
},
|
|
},
|
|
- "import " "axios, " "{bar, " "foo} from " '"axios"',
|
|
|
|
|
|
+ "axios",
|
|
|
|
+ {"foo", "bar"},
|
|
),
|
|
),
|
|
],
|
|
],
|
|
)
|
|
)
|
|
-def test_compile_import_statement(lib: str, fields: Set[ImportVar], output: str):
|
|
|
|
|
|
+def test_compile_import_statement(
|
|
|
|
+ fields: Set[ImportVar], test_default: str, test_rest: str
|
|
|
|
+):
|
|
"""Test the compile_import_statement function.
|
|
"""Test the compile_import_statement function.
|
|
|
|
|
|
Args:
|
|
Args:
|
|
- lib: The library name.
|
|
|
|
fields: The fields to import.
|
|
fields: The fields to import.
|
|
- output: The expected output.
|
|
|
|
|
|
+ test_default: The expected output of default library.
|
|
|
|
+ test_rest: The expected output rest libraries.
|
|
"""
|
|
"""
|
|
- assert utils.compile_import_statement(lib, fields) == output
|
|
|
|
|
|
+ default, rest = utils.compile_import_statement(fields)
|
|
|
|
+ assert default == test_default
|
|
|
|
+ assert rest == test_rest
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
@pytest.mark.parametrize(
|
|
- "import_dict,output",
|
|
|
|
|
|
+ "import_dict,test_dicts",
|
|
[
|
|
[
|
|
- ({}, ""),
|
|
|
|
|
|
+ ({}, []),
|
|
(
|
|
(
|
|
{"axios": {ImportVar(tag="axios", is_default=True)}},
|
|
{"axios": {ImportVar(tag="axios", is_default=True)}},
|
|
- 'import axios from "axios"',
|
|
|
|
|
|
+ [{"lib": "axios", "default": "axios", "rest": set()}],
|
|
),
|
|
),
|
|
(
|
|
(
|
|
{"axios": {ImportVar(tag="foo"), ImportVar(tag="bar")}},
|
|
{"axios": {ImportVar(tag="foo"), ImportVar(tag="bar")}},
|
|
- 'import {bar, foo} from "axios"',
|
|
|
|
|
|
+ [{"lib": "axios", "default": "", "rest": {"foo", "bar"}}],
|
|
),
|
|
),
|
|
(
|
|
(
|
|
{
|
|
{
|
|
@@ -63,52 +67,61 @@ def test_compile_import_statement(lib: str, fields: Set[ImportVar], output: str)
|
|
},
|
|
},
|
|
"react": {ImportVar(tag="react", is_default=True)},
|
|
"react": {ImportVar(tag="react", is_default=True)},
|
|
},
|
|
},
|
|
- 'import axios, {bar, foo} from "axios"\nimport react from "react"',
|
|
|
|
|
|
+ [
|
|
|
|
+ {"lib": "axios", "default": "axios", "rest": {"foo", "bar"}},
|
|
|
|
+ {"lib": "react", "default": "react", "rest": set()},
|
|
|
|
+ ],
|
|
),
|
|
),
|
|
(
|
|
(
|
|
{"": {ImportVar(tag="lib1.js"), ImportVar(tag="lib2.js")}},
|
|
{"": {ImportVar(tag="lib1.js"), ImportVar(tag="lib2.js")}},
|
|
- 'import "lib1.js"\nimport "lib2.js"',
|
|
|
|
|
|
+ [
|
|
|
|
+ {"lib": "lib1.js", "default": "", "rest": set()},
|
|
|
|
+ {"lib": "lib2.js", "default": "", "rest": set()},
|
|
|
|
+ ],
|
|
),
|
|
),
|
|
(
|
|
(
|
|
{
|
|
{
|
|
"": {ImportVar(tag="lib1.js"), ImportVar(tag="lib2.js")},
|
|
"": {ImportVar(tag="lib1.js"), ImportVar(tag="lib2.js")},
|
|
"axios": {ImportVar(tag="axios", is_default=True)},
|
|
"axios": {ImportVar(tag="axios", is_default=True)},
|
|
},
|
|
},
|
|
- 'import "lib1.js"\nimport "lib2.js"\nimport axios from "axios"',
|
|
|
|
|
|
+ [
|
|
|
|
+ {"lib": "lib1.js", "default": "", "rest": set()},
|
|
|
|
+ {"lib": "lib2.js", "default": "", "rest": set()},
|
|
|
|
+ {"lib": "axios", "default": "axios", "rest": set()},
|
|
|
|
+ ],
|
|
),
|
|
),
|
|
],
|
|
],
|
|
)
|
|
)
|
|
-def test_compile_imports(
|
|
|
|
- import_dict: imports.ImportDict, output: str, windows_platform: bool
|
|
|
|
-):
|
|
|
|
|
|
+def test_compile_imports(import_dict: imports.ImportDict, test_dicts: List[dict]):
|
|
"""Test the compile_imports function.
|
|
"""Test the compile_imports function.
|
|
|
|
|
|
Args:
|
|
Args:
|
|
import_dict: The import dictionary.
|
|
import_dict: The import dictionary.
|
|
- output: The expected output.
|
|
|
|
- windows_platform: whether system is windows.
|
|
|
|
|
|
+ test_dicts: The expected output.
|
|
"""
|
|
"""
|
|
- assert utils.compile_imports(import_dict) == (
|
|
|
|
- output.replace("\n", "\r\n") if windows_platform else output
|
|
|
|
- )
|
|
|
|
|
|
+ imports = utils.compile_imports(import_dict)
|
|
|
|
+ for import_dict, test_dict in zip(imports, test_dicts):
|
|
|
|
+ assert import_dict["lib"] == test_dict["lib"]
|
|
|
|
+ assert import_dict["default"] == test_dict["default"]
|
|
|
|
+ assert import_dict["rest"] == test_dict["rest"]
|
|
|
|
|
|
|
|
|
|
-@pytest.mark.parametrize(
|
|
|
|
- "name,value,output",
|
|
|
|
- [
|
|
|
|
- ("foo", "bar", 'const foo = "bar"'),
|
|
|
|
- ("num", 1, "const num = 1"),
|
|
|
|
- ("check", False, "const check = false"),
|
|
|
|
- ("arr", [1, 2, 3], "const arr = [1, 2, 3]"),
|
|
|
|
- ("obj", {"foo": "bar"}, 'const obj = {"foo": "bar"}'),
|
|
|
|
- ],
|
|
|
|
-)
|
|
|
|
-def test_compile_constant_declaration(name: str, value: str, output: str):
|
|
|
|
- """Test the compile_constant_declaration function.
|
|
|
|
|
|
+# @pytest.mark.parametrize(
|
|
|
|
+# "name,value,output",
|
|
|
|
+# [
|
|
|
|
+# ("foo", "bar", 'const foo = "bar"'),
|
|
|
|
+# ("num", 1, "const num = 1"),
|
|
|
|
+# ("check", False, "const check = false"),
|
|
|
|
+# ("arr", [1, 2, 3], "const arr = [1, 2, 3]"),
|
|
|
|
+# ("obj", {"foo": "bar"}, 'const obj = {"foo": "bar"}'),
|
|
|
|
+# ],
|
|
|
|
+# )
|
|
|
|
+# def test_compile_constant_declaration(name: str, value: str, output: str):
|
|
|
|
+# """Test the compile_constant_declaration function.
|
|
|
|
|
|
- Args:
|
|
|
|
- name: The name of the constant.
|
|
|
|
- value: The value of the constant.
|
|
|
|
- output: The expected output.
|
|
|
|
- """
|
|
|
|
- assert utils.compile_constant_declaration(name, value) == output
|
|
|
|
|
|
+# Args:
|
|
|
|
+# name: The name of the constant.
|
|
|
|
+# value: The value of the constant.
|
|
|
|
+# output: The expected output.
|
|
|
|
+# """
|
|
|
|
+# assert utils.compile_constant_declaration(name, value) == output
|