Example #1
0
def step_impl(context):  # noqa: F811
    saveproj = random_string()
    context.projpath = saveproj + '.project'
    context.projecttextfile = random_string() + '.txt'
    context.cleanup.append(context.projpath)
    context.cleanup.append(context.projecttextfile)

    root = Element('project')
    text = Element('text', name=context.projecttextfile)
    context.random_text = random_string()
    text.text = context.random_text + '\n'
    root.append(text)

    with open(context.projpath, 'w') as fh:
        fh.write(tostring(root, pretty_print=True).decode())

    assert os.path.exists(context.projpath)

    context.projpath = random_string() + '.project'
    context.cleanup.append(context.projpath)

    root = Element('project')
    text = Element('project', name=saveproj)
    root.append(text)
    log.info(f'{context.random_text=} up here where it started')
    with open(context.projpath, 'w') as fh:
        fh.write(tostring(root, pretty_print=True).decode())
    assert os.path.exists(context.projpath)
Example #2
0
def step_impl(context):  # noqa: F811
    context.macrosetRandomName = random_string()
    context.temp_directory = random_string()
    context.cleanup.append(context.macrosetRandomName)
    context.cleanup.append(context.temp_directory)
    run_assemble(context, context.source['macro'][0]['path'],
                 context.source['macro'][1]['path'], '--name',
                 context.macrosetRandomName, '--output',
                 context.temp_directory)
    assert b'Error' not in context.stderr, context.stderr
Example #3
0
def step_impl(context):  # noqa: F811
    context.projpath = random_string() + '.project'
    context.projecttextfile = 'README.txt'
    context.cleanup.append(context.projpath)
    context.cleanup.append(context.projecttextfile)

    root = Element('project')
    text = Element('text')
    context.random_text = text.text = random_string()
    root.append(text)

    with open(context.projpath, 'w') as fh:
        fh.write(tostring(root, pretty_print=True).decode())
    assert os.path.exists(context.projpath)
Example #4
0
def step_impl(context):  # noqa: F811
    context.projpath = random_string() + '.project'
    root = Element('project')
    context.macrosetname = random_string()
    macroset = Element('macroset', name=context.macrosetname)
    context.macrosetfilename = context.macrosetname + '.' + tagset.macroset.ext
    macroset.append(Element('macro', name=context.source['macro'][0]['path']))
    macroset.append(Element('macro', name=context.source['macro'][1]['path']))
    root.append(macroset)
    root.append(Element('token', name=context.source['token']['src'][0]))
    root.append(Element('properties', name=context.source['props'][0]))
    context.cleanup.append(context.projpath)
    context.cleanup.append(context.macrosetfilename)
    with open(context.projpath, 'w') as fh:
        fh.write(tostring(root, pretty_print=True).decode())
Example #5
0
def step_impl(context):  # noqa: F811
    context.temp_directory = random_string()
    run_assemble(context, context.tokenpath, '--output',
                 context.temp_directory)
    assert b'Error' not in context.stderr, context.stderr
    context.tokenfilename = os.path.basename(
        context.tokenpath) + '.' + tagset.token.ext
 def test_macro_macro_assemble_save_as(self, tmpdir):
     newname = random_string()
     m = GetAsset('macro/MVMacro1.xml')
     assert m is not None
     assert m.xmlfile == 'macro/MVMacro1.xml'
     m.assemble(save_name=newname)
     assert os.path.exists(newname + '.mtmacro')
 def test_properties_asset_assemble(self, tmpdir):
     newname = random_string()
     newfilename = newname + '.' + tagset.properties.ext
     m = GetAsset('MVProps/content.xml')
     assert m is not None
     m.assemble(save_name=newname)
     assert os.path.exists(newfilename), f'{newfilename} was not found'
Example #8
0
def step_impl(context):  # noqa: F811
    context.macrosetname = random_string()
    # first.project refers to second.project and has a macrosetname with macro/MVMacro1
    # second.project refers to third.project and has a macrosetname with macro/MVMacro2
    # third.project has a macrosetname with macro/MVMacro3
    with open('first.project', 'w') as fh:
        fh.write(f'''<project>
        <project name="second"/>
        <macroset name="{context.macrosetname}">
            <macro name="src/macro/MVMacro1"/>
        </macroset>
        </project>''')
    with open('second.project', 'w') as fh:
        fh.write(f'''<project>
        <project name="third"/>
        <macroset name="{context.macrosetname}">
            <macro name="src/macro/MVMacro2"/>
        </macroset>
        </project>''')
    with open('third.project', 'w') as fh:
        fh.write(f'''<project>
        <macroset name="{context.macrosetname}">
            <macro name="src/macro/MVMacro3"/>
        </macroset>
        </project>''')

    assert os.path.exists('first.project')
    assert os.path.exists('second.project')
    assert os.path.exists('third.project')
Example #9
0
def step_impl(context):  # noqa: F811
    content_xml = os.path.join(context.tokenpath, 'content.xml')
    xml = objectify.parse(content_xml)
    xml.getroot().name = DataElement('Lib:' + random_string())
    xml.write(content_xml, pretty_print=True)
    assert '<name>Lib:' in open(content_xml).read(
    ), f"Name not Lib: in {content_xml} in '{os.getcwd()}'"
 def test_properties_asset_extract(self, tmpdir):
     newname = random_string()
     m = GetAsset('MVProps/content.xml')
     assert m is not None
     m.extract(save_name=newname)
     for filename in 'content.xml', 'properties.xml':
         file_exists = os.path.join(newname, filename)
         assert os.path.exists(file_exists), f'{file_exists} does not exist'
Example #11
0
def step_impl(context):  # noqa: F811
    m = GetAsset(context.macrosrc)
    m.root.command = objectify.StringElement(git_comment_str + '\n' +
                                             m.root.command.text)
    context.macroname = random_string()
    m.assemble(context.macroname)
    assert os.path.exists(
        context.macrofile), f"{context.macrofile} not found in '{os.getcwd()}'"
Example #12
0
def step_impl(context):  # noqa: F811
    context.tokenelement = '_' + random_string()
    context.tokenname = os.path.join('output',
                                     os.path.basename(context.tokenfile))
    with open('config.ini', 'w') as fh:
        fh.write('[assemble]\ndirectory = output\nLibTokenGitTagElement = ' +
                 context.tokenelement + '\n\n[extract]\ndirectory = .')
    assert 'LibTokenGitTagElement' in open('config.ini').read()
Example #13
0
def step_impl(context):  # noqa: F811
    context.temp_directory = random_string()
    assert os.path.exists(
        context.projpath
    ), f'{context.projpath} does not exist in {os.getcwd()=}'
    run_assemble(context, context.projpath, '--output', context.temp_directory)
    context.projcontents = open(context.projpath).read()
    assert b'Error' not in context.stderr, f'Error found in {context.stderr} when running {context.assemble} {context.projpath} --output {context.temp_directory}'
 def test_properties_append_string(self, tmpdir):
     newname = random_string()
     newfilename = newname + '.' + tagset.properties.ext
     m = GetAsset('MVProps/content.xml')
     assert m is not None
     m.append('MVProps2', 'tokenTypeMap', 'entry[string="Second"]')
     m.assemble(save_name=newname)
     assert os.path.exists(newfilename)
     n = GetAsset(newfilename)
     assert n.xml.find('tokenTypeMap/entry[string="Second"]') is not None
Example #15
0
def step_impl(context):  # noqa: F811
    assert 'macro' in context.source
    assert len(context.source['macro']) > 1
    context.macrosetname = random_string()
    run_assemble(context, '--name', context.macrosetname,
                 context.source['macro'][0]['path'],
                 context.source['macro'][1]['path'])
    context.macrosetfilename = context.macrosetname + '.' + tagset.macroset.ext
    assert os.path.exists(
        os.path.join('output', context.macrosetfilename
                     )), f"no {context.macrosetfilename} in '{os.getcwd()}'"
 def test_macro_macroset_assemble_save_as(self, tmpdir):
     newname = random_string()
     newfilename = newname + '.' + tagset.macroset.ext
     assert os.path.exists('MVMacroSet.mtmacset')
     m = GetAsset('MVMacroSet.mtmacset')
     assert m is not None
     assert m.best_name(newname) == newname
     # assert False, f'{m.xmlfile} is m.xmlfile'
     # assert False, f'{m.dirname} is m.dirname'
     m.assemble(save_name=newname)
     assert os.path.exists(newfilename), f'{newfilename} does not exist'
 def test_macro_extract_git_sha_remove(self, tmpdir):
     macroname = random_string()
     m = GetAsset('macro/MVMacro1')
     assert m is not None
     m.root.label = objectify.StringElement(macroname)
     m.assemble(save_name=macroname)
     m = GetAsset(macroname + '.' + tagset.macro.ext)
     assert m is not None
     assert m.is_macro
     m.extract()
     assert os.path.exists(f'macro/{macroname}.xml'), f'expected macro/{macroname}.xml in {glob("**/*")=}'
     assert os.path.exists(f'macro/{macroname}.command'), f'{glob("**/*")=}'
Example #18
0
def step_impl(context):  # noqa: F811
    assert 'token' in context.source
    assert 'src' in context.source['token']
    assert len(context.source['token']['src']) > 1
    context.tokenpath = context.source['token']['src'][1]
    context.tokenname = 'Lib:' + random_string()
    m = GetAsset(context.tokenpath)
    assert m is not None
    m.root.name = context.tokenname
    filename = context.tokenname.replace(':', '-')
    m.assemble(filename)
    context.tokenfile = filename + '.' + tagset.token.ext
    assert os.path.exists(
        context.tokenfile
    ), f'{context.tokenfile} does not exist in \'{os.getcwd()}\''
 def test_macro_append_macro_object(self, tmpdir):
     newname = random_string()
     newfilename = newname + '.' + tagset.macroset.ext
     m = GetAsset('macro/MVMacro1.xml')
     n = GetAsset('macro/MVMacro2.xml')
     assert m is not None
     assert m.is_macro
     assert n is not None
     assert n.is_macro
     m.append(n)
     # This is a weird one, it doesn't actually change
     # the type of object, just the contents, but since
     # they share the same base object, it works.
     assert m.tag == tagset.macroset.tag
     assert m.is_macroset
     m.assemble(save_name=newname)
     assert os.path.exists(newfilename)
     o = GetAsset(newfilename)
     assert o is not None
     assert o.is_macroset
     assert o.tag == tagset.macroset.tag
     assert type(o) == MTMacroSet
     for tag in [x.tag for x in o.root.iterchildren()]:
         assert tag == tagset.macro.tag
 def test_macro_with_missing_xml_file(self, tmpdir):
     target = 'macro/' + random_string() + '.xml'
     assert not os.path.exists(target)
     with pytest.raises(FileNotFoundError):
         m = GetAsset(target)
         assert m is not None
 def test_properties_append_invalid_string(self, tmpdir):
     fakename = random_string()
     m = GetAsset('MVProps/content.xml')
     assert m is not None
     with pytest.raises(FileNotFoundError):
         m.append(fakename, 'tokenTypeMap', 'entry[string="Second"]')
    def setup_method(self, tmpdir):
        test_start_dir = os.getcwd()
        os.chdir(tmpdir)
        mvp = os.path.join(test_start_dir, 'test/data/MinViable')
        for zf in glob(mvp + '/*.zip'):
            with zipfile.ZipFile(zf, 'r') as zip_ref:
                zip_ref.extractall(tmpdir)
        self.source = [
            {'name': random_string(), 'in': ['macroset', 'token']},
            {'name': random_string(), 'in': ['macro', 'text']},
            {'name': random_string(), 'in': ['macroset', 'project']},
            {'name': random_string(), 'in': ['macro', 'text'], 'textname': random_string()},
        ]
        # create a project file with macroset, properties, and token
        p1 = self.source[0]
        p1['filename'] = p1['name'] + '.' + tagset.project.ext
        root = Element('project')
        p1['macrosetname'] = random_string()
        macroset = Element('macroset', name=p1['macrosetname'])
        p1['macrosetfilename'] = p1['macrosetname'] + '.' + tagset.macroset.ext
        macroset.append(Element('macro', name="macro/MVMacro1"))
        macroset.append(Element('macro', name="macro/MVMacro2"))
        root.append(macroset)
        root.append(Element('properties', name="MVProps"))
        root.append(Element('token', name="MVToken"))
        with open(p1['filename'], 'w') as fh:
            fh.write(tostring(root, pretty_print=True).decode())

        # create a project with macro and text (unnamed)
        p2 = self.source[1]
        p2['filename'] = p2['name'] + '.' + tagset.project.ext
        root = Element('project')
        root.append(Element('macro', name="macro/MVMacro1"))
        text = Element('text')
        p2['textbody'] = random_string()
        text.text = p2['textbody'] + '\n'
        root.append(text)
        with open(p2['filename'], 'w') as fh:
            fh.write(tostring(root, pretty_print=True).decode())

        # create a project with macroset and project (referring to #2 above)
        p3 = self.source[2]
        p3['filename'] = p3['name'] + '.' + tagset.project.ext
        root = Element('project')
        p3['macrosetname'] = random_string()
        macroset = Element('macroset', name=p3['macrosetname'])
        self.macrosetfilename = p3['macrosetname'] + '.' + tagset.macroset.ext
        macroset.append(Element('macro', name="macro/MVMacro1"))
        macroset.append(Element('macro', name="macro/MVMacro2"))
        root.append(macroset)
        root.append(Element('project', name=self.source[1]['filename']))
        with open(p3['filename'], 'w') as fh:
            fh.write(tostring(root, pretty_print=True).decode())

        # create a project with macro and text with name
        p4 = self.source[3]
        p4['filename'] = self.source[3]['name'] + '.' + tagset.project.ext
        root = Element('project')
        p4['macrosetname'] = random_string()
        root.append(Element('macro', name="macro/MVMacro2"))
        p4['randomtext'] = random_string()
        p4['textfile'] = random_string() + '.txt'
        text = Element('text', name=p4['textfile'])
        text.text = p4['randomtext'] + '\n'
        root.append(text)
        with open(p4['filename'], 'w') as fh:
            fh.write(tostring(root, pretty_print=True).decode())

        try:
            yield
        finally:
            os.chdir(test_start_dir)