Beispiel #1
0
 def test_fullPyComp_Default(self):
     r=vbuild.VBuild("c.vue",self.cj)
     self.assertEqual(self.nbPythonLibIncluded(r),0)    # no py no lib
     r+=vbuild.VBuild("c1.vue",self.cp)
     r+=vbuild.VBuild("c2.vue",self.cp)
     self.assertTrue(self.isPythonComp(r))
     self.assertEqual(self.nbPythonLibIncluded(r),2)    # each comp got its own std methods
Beispiel #2
0
    def test_sass(self):
        if not vbuild.hasSass: self.skipTest("Don't test sass (miss pyScss)")

        h="""<template><div>XXX</div></template>
        <Style scoped lang="sass">
        body {
            font: 2px *3;
            color: red + green;
        }
        </style>"""
        r=vbuild.VBuild("comp.vue",h)
        self.assertTrue("6px" in r.style)
        self.assertTrue("#ff8000" in r.style)

        h="""<template><div>XXX</div></template>
        <Style scoped lang="sass">
        body {
            font: $unknown;
        }
        </style>"""
        r=vbuild.VBuild("comp.vue",h)
        with self.assertRaises(vbuild.VBuildException):     # vbuild.VBuildException: Component 'comp.vue' got a CSS-PreProcessor trouble : Error evaluating expression:
            r.style

        # ensure inline def class are OK
        h="""<template><div>XXX</div></template>
        <Style scoped lang="sass">
        :scope {
            color:blue;

            div {color:red}
        }
        </style>"""
        r=vbuild.VBuild("comp.vue",h)
        self.assertEqual(r.style,"""*[data-comp] {color: blue; }\n*[data-comp] div {color: red; }""")
Beispiel #3
0
 def test_fullPyComp_None(self):
     vbuild.fullPyComp=None
     r=vbuild.VBuild("c.vue",self.cj)
     self.assertEqual(self.nbPythonLibIncluded(r),0)    # no py no lib
     r+=vbuild.VBuild("c1.vue",self.cp)
     r+=vbuild.VBuild("c2.vue",self.cp)
     self.assertTrue(self.isPythonComp(r))
     self.assertEqual(self.nbPythonLibIncluded(r),0)    # nothing is included, it's up to you
Beispiel #4
0
 def test_fullPyComp_False(self):
     vbuild.fullPyComp=False
     r=vbuild.VBuild("c.vue",self.cj)
     self.assertEqual(self.nbPythonLibIncluded(r),0)    # no py no lib
     r+=vbuild.VBuild("c1.vue",self.cp)
     r+=vbuild.VBuild("c2.vue",self.cp)
     self.assertTrue(self.isPythonComp(r))
     self.assertEqual(self.nbPythonLibIncluded(r),1)    # the full std lib is included
Beispiel #5
0
 def test_composant_add(self):
     c=vbuild.VBuild("c.vue","""<template><div>XXX</div></template>""")
     d=vbuild.VBuild("d.vue","""<template><div>XXX</div></template>""")
     cc=sum([c,d])
     self.assertTrue(cc.html.count("<div data-c>XXX</div>")==1)
     self.assertTrue(cc.html.count("<div data-d>XXX</div>")==1)
     self.assertTrue(cc.script.count("var c = Vue.component('c', {template:'#tpl-c',});")==1)
     self.assertTrue(cc.script.count("var d = Vue.component('d', {template:'#tpl-d',});")==1)
Beispiel #6
0
def testVoidElements_closed():
    t = """<template>
<div>
    <hr/>
    hello {{name}}<br/>
    <hr>
</div>
</template>
<style>
h1 {color:blue}
</style>
<script>
export defailt {
    props:["name"],
}
</script>
    """
    rendered = """<style>
h1 {color:blue}
</style>
<script type="text/x-template" id="tpl-jo"><div data-jo>
    <hr/>
    hello {{name}}<br/>
    <hr>
</div></script>
<script>
var jo = Vue.component('jo', {template:'#tpl-jo',
    props:["name"],
});
</script>
"""
    r = vbuild.VBuild("jo.vue", t)
    assert str(r) == rendered
Beispiel #7
0
 def test_1(self):
     vbuild.transScript=lambda x: x.upper()
     vbuild.transStyle=lambda x: x+"/*Hello*/"
     vbuild.transHtml=lambda x: x.upper()
     r=vbuild.VBuild("toto.vue","<template><div></div></template>")
     self.assertTrue("VUE.COMPONENT('TOTO'" in r.script)
     self.assertTrue('<script type="text/x-template" id="tpl-toto"><DIV DATA-TOTO></DIV></script>' in r.html)
     self.assertEqual(r.style,"/*Hello*/")
Beispiel #8
0
def test_composant_min():
    h = """
<template>
  <div>Load</div>
</template>
"""
    r = vbuild.VBuild("name.vue", h)
    assert "<div data-name>" in str(r)
    assert '<script type="text/x-template" id="tpl-name">' in str(r)
    assert "var name = Vue.component('name', {template:'#tpl-name'," in str(r)
Beispiel #9
0
def test_pycomp_onlineClosurable():
    """ Ensure python component produce a JS which is closure's online ready !"""
    cp = """<template><div>yo</div></template><script>class Component: pass</script>"""
    try:
        default = vbuild.fullPyComp
        vbuild.fullPyComp = False
        r = vbuild.VBuild("c.vue", cp)
        x = vbuild.jsminOnline(r.script)
        assert x
    finally:
        vbuild.fullPyComp = default
Beispiel #10
0
    def test_pickable(self):  # so it's GAE memcach'able !
        h = """
<template>
  <div>Load</div>
</template>
"""
        import pickle
        r = vbuild.VBuild("name.vue", h)
        f_string = pickle.dumps(r)
        f_new = pickle.loads(f_string)
        self.assertEqual(str(r), str(f_new))
Beispiel #11
0
def test_less():
    h = """<template><div>XXX</div></template>
    <Style scoped Lang = "leSS" >
    body {
        border-width: 2px *3;
    }
    </style>"""
    r = vbuild.VBuild("comp.vue", h)
    assert "6px" in r.style

    h = """<template><div>XXX</div></template>
    <Style scoped lang="less">
    body {
        font: @unknown;
    }
    </style>"""
    r = vbuild.VBuild("comp.vue", h)
    with pytest.raises(
            vbuild.VBuildException
    ):  # vbuild.VBuildException: Component 'comp.vue' got a CSS-PreProcessor trouble : Error evaluating expression:
        r.style
Beispiel #12
0
    def test_less(self):
        if not vbuild.hasLess: self.skipTest("Cant test Less (instal lesscpy)")

        h="""<template><div>XXX</div></template>
        <Style scoped Lang = "leSS" >
        body {
            border-width: 2px *3;
        }
        </style>"""
        r=vbuild.VBuild("comp.vue",h)
        self.assertTrue("6px" in r.style)

        h="""<template><div>XXX</div></template>
        <Style scoped lang="less">
        body {
            font: @unknown;
        }
        </style>"""
        r=vbuild.VBuild("comp.vue",h)
        with self.assertRaises(vbuild.VBuildException):     # vbuild.VBuildException: Component 'comp.vue' got a CSS-PreProcessor trouble : Error evaluating expression:
            r.style
Beispiel #13
0
def test_names():
    h = """<template><div>XXX</div></template>"""
    assert vbuild.VBuild("mycomp.vue", h).tags[0] == "mycomp"
    assert vbuild.VBuild("jo/mycomp.vue", h).tags[0] == "mycomp"
    assert vbuild.VBuild("jo/mycomp.vuec", h).tags[0] == "mycomp"
    assert vbuild.VBuild("jo/mycomp.vu", h).tags[0] == "mycomp"
    assert vbuild.VBuild("jo/mycomp", h).tags[0] == "mycomp"
    with pytest.raises(vbuild.VBuildException):
        r = vbuild.VBuild("", h)  # Component %s should be named
    with pytest.raises(vbuild.VBuildException):
        r = vbuild.VBuild(None, h)  # Component %s should be named
Beispiel #14
0
    def test_script_good(self):    # so it's GAE memcach'able !
        h="""
<template>
  <div>Load</div>
</template>
<script>
export default {
    mounted() {}
}
</script>
"""
        r=vbuild.VBuild("name.vue",h)
        self.assertEqual(r.script,"""var name = Vue.component('name', {template:'#tpl-name',\n    mounted() {}\n});""")
Beispiel #15
0
 def test_names(self):
     h="""<template><div>XXX</div></template>"""
     self.assertEqual(vbuild.VBuild("mycomp.vue",h).tags[0],"mycomp")
     self.assertEqual(vbuild.VBuild("jo/mycomp.vue",h).tags[0],"mycomp")
     self.assertEqual(vbuild.VBuild("jo/mycomp.vuec",h).tags[0],"mycomp")
     self.assertEqual(vbuild.VBuild("jo/mycomp.vu",h).tags[0],"mycomp")
     self.assertEqual(vbuild.VBuild("jo/mycomp",h).tags[0],"mycomp")
     with self.assertRaises(vbuild.VBuildException):
         r=vbuild.VBuild("",h) # Component %s should be named
     with self.assertRaises(vbuild.VBuildException):
         r=vbuild.VBuild(None,h) # Component %s should be named
Beispiel #16
0
def test_sass():
    h = """<template><div>XXX</div></template>
    <Style scoped lang="sass">
    body {
        font: 2px *3;
        color: red + green;
    }
    </style>"""
    r = vbuild.VBuild("comp.vue", h)
    assert "6px" in r.style
    assert "#ff8000" in r.style

    h = """<template><div>XXX</div></template>
    <Style scoped lang="sass">
    body {
        font: $unknown;
    }
    </style>"""
    r = vbuild.VBuild("comp.vue", h)
    with pytest.raises(
        vbuild.VBuildException
    ):  # vbuild.VBuildException: Component 'comp.vue' got a CSS-PreProcessor trouble : Error evaluating expression:
        r.style

    # ensure inline def class are OK
    h = """<template><div>XXX</div></template>
    <Style scoped lang="sass">
    :scope {
        color:blue;

        div {color:red}
    }
    </style>"""
    r = vbuild.VBuild("comp.vue", h)
    assert (
        r.style == """*[data-comp] {color: blue; }\n*[data-comp] div {color: red; }"""
    )
Beispiel #17
0
def test_1():
    try:
        vbuild.transScript = lambda x: x.upper()
        vbuild.transStyle = lambda x: x + "/*Hello*/"
        vbuild.transHtml = lambda x: x.upper()
        r = vbuild.VBuild("toto.vue", "<template><div></div></template>")
        assert "VUE.COMPONENT('TOTO'" in r.script
        assert (
            '<script type="text/x-template" id="tpl-toto"><DIV DATA-TOTO></DIV></script>'
            in r.html)
        assert r.style == "/*Hello*/"
    finally:
        vbuild.transScript = lambda x: x
        vbuild.transStyle = lambda x: x
        vbuild.transHtml = lambda x: x
Beispiel #18
0
def test_composant_complet_trans():
    h = """
<template>
  <div>
    {{c}} <button @click="inc">++</button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      c: 0,
    }
  },
  methods: {
    inc() {this.c+=1;}
  }
}
</script>
<style scoped>
:scope {
    padding:4px;
    background: yellow
}
  button {background:red}
</style>
<style>
  button {background:black}
</style>
"""
    oh = vbuild.transHtml
    oj = vbuild.transScript
    oc = vbuild.transStyle
    try:
        vbuild.transHtml = lambda x: "h"
        vbuild.transScript = lambda x: "j"
        vbuild.transStyle = lambda x: "c"
        r = vbuild.VBuild("name.vue", h)
        assert r.html, '<script type="text/x-template" id="tpl-name">h</script>'
        assert r.script, "j"
        assert r.style, "c"
    finally:
        vbuild.transHtml = oh
        vbuild.transScript = oj
        vbuild.transStyle = oc
Beispiel #19
0
    def test_composant_complet(self):
        h = """
<template>
  <div>
    {{c}} <button @click="inc">++</button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      c: 0,
    }
  },
  methods: {
    inc() {this.c+=1;}
  }
}
</script>
<style>
:scope {
    padding:4px;
    background: yellow
}
  button {background:red}
</style>
"""
        r = vbuild.VBuild("name.vue", h)
        #~ print(r, file=sys.stdout)
        self.assertEqual(r.tags, ["name"])

        self.assertEqual(str(r).count("div[data-name]"), 2)
        self.assertFalse(":scope" in str(r))
        self.assertTrue("<div data-name>" in str(r))
        self.assertTrue(
            '<script type="text/x-template" id="tpl-name">' in str(r))
        self.assertTrue(
            "var name = Vue.component('name', {template:'#tpl-name'," in str(
                r))
Beispiel #20
0
    def test_ko_syntax(self):
        c="""<template>
    <div>
        {{name}} {{cpt}}
        <button @click="inc()">++</button>
    </div>
</template>
<script lang="python">

class Component:
    def __init__(self, name):
        self.cpt=0

    def inc(self)           # miss : !!!
        self.cpt+=1

</script>
<style scoped>
    :scope {background:#EEE}
</style>"""
        with self.assertRaises(vbuild.VBuildException): # Python Component 'pyc.vue' is broken
            vbuild.VBuild("pyc.vue",c)
Beispiel #21
0
    def test_ko_semantic(self):
        c="""<template>
    <div>
        {{name}} {{cpt}}
        <button @click="inc()">++</button>
    </div>
</template>
<script lang="python">

class ComponentV0:                  # bad class name
    def __init__(self, name):
        self.cpt=0

    def inc(self):
        self.cpt+=1

</script>
<style scoped>
    :scope {background:#EEE}
</style>"""
        with self.assertRaises(vbuild.VBuildException): # Component pyc.vue contains a bad script
            vbuild.VBuild("pyc.vue",c)
Beispiel #22
0
def test_composant_complet():
    h = """
<template>
  <div>
    {{c}} <button @click="inc">++</button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      c: 0,
    }
  },
  methods: {
    inc() {this.c+=1;}
  }
}
</script>
<style scoped>
:scope {
    padding:4px;
    background: yellow
}
  button {background:red}
</style>
<style>
  button {background:black}
</style>
"""
    r = vbuild.VBuild("name.vue", h)
    assert r.tags == ["name"]
    assert r.style.count("*[data-name]") == 2
    assert r.style.count("background") == 3

    assert ":scope" not in repr(r)
    assert "<div data-name>" in repr(r)
    assert '<script type="text/x-template" id="tpl-name">' in repr(r)
    assert "var name = Vue.component('name', {template:'#tpl-name'," in repr(r)
Beispiel #23
0
    def test_ok(self):
        c="""<template>
    <div>
        {{name}} {{cpt}}
        <button @click="inc()">++</button>
    </div>
</template>
<script lang="python">

class Component:
    def __init__(self, name):
        self.cpt=0

    def inc(self):
        self.cpt+=1

</script>
<style scoped>
    :scope {background:#EEE}
</style>"""
        r=vbuild.VBuild("pyc.vue",c)
        self.assertTrue("_pyfunc_op_instantiate" in r.script)
        self.assertTrue("Vue.component(" in r.script)
Beispiel #24
0
    def change(self):
        self.id+="x"
</script>
<style scoped lang="sass">
:scope {border:2px solid green;margin:$v;padding:$v;}
</style>

"""
try:
    vbuild.partial = "$v: 12px;"
    # ~ vbuild.fullPyComp=False

    dest = os.path.basename(__file__)[:-3] + ".html"

    with open(dest, "w+") as fid:
        v = vbuild.VBuild("comp.vue", cc) + vbuild.VBuild("mother.vue", cm)
        html = v.html
        style = v.style
        # script=vbuild.jsmin(v.script)
        script = v.script

        fid.write("""
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>%(style)s</style>
    %(html)s
    <script>%(script)s</script>
    <div id="app">
        <mother/>
    </div>
    <script>new Vue({el:"#app"})</script>    
    """ % locals())
Beispiel #25
0
def test_bad_script_not_closed():
    h = """<template> <div>XXX</div></template><script> gdsf gfds """
    r = vbuild.VBuild("comp.vue", h)  # Component %s contains a bad script
    assert r.script
Beispiel #26
0
def test_bad_script_bad():
    h = """<template> <div>XXX</div></template><script> gdsf gfds </script>"""
    with pytest.raises(vbuild.VBuildException):
        r = vbuild.VBuild("comp.vue", h)  # Component %s contains a bad script
Beispiel #27
0
def test_bad_no_template():
    h = """<templite type="xxx"> <div>XXX</div> <div>XXX</div> </templite>"""
    with pytest.raises(vbuild.VBuildException):
        r = vbuild.VBuild("comp.vue",
                          h)  # Component comp.vue doesn't have a template
Beispiel #28
0
    def test_base(self):
        r=vbuild.VBuild("c.vue",self.cj)
        self.assertFalse(self.isPythonComp(r))  # comp is js

        r=vbuild.VBuild("c.vue",self.cp)
        self.assertTrue(self.isPythonComp(r))   # comp is py
Beispiel #29
0
def test_bad_more_than_one_root():
    h = """<template type="xxx"> <div>XXX</div> <div>XXX</div> </template>"""
    with pytest.raises(vbuild.VBuildException):
        r = vbuild.VBuild(
            "mycomp.vue",
            h)  # Component mycomp.vue can have only one top level tag
Beispiel #30
0
def test_bad_composant_add():
    c = vbuild.VBuild("c.vue", """<template><div>XXX</div></template>""")
    with pytest.raises(vbuild.VBuildException):
        cc = sum([c, c])  # You can't have multiple set(['c'])