コード例 #1
0
    def test_asset_with_token(self, tmpdir):
        dn = os.path.join(tmpdir, 'MTToken')
        os.makedirs(dn, exist_ok=True)
        fn = os.path.join(dn, 'content.xml')
        with open(fn, 'w') as f:
            f.write('<' + tagset.token.tag + '>')
            f.write('<name>Test-MTToken</name>')
            f.write('</' + tagset.token.tag + '>')
        m = GetAsset(dn)
        assert m.is_properties is False
        assert m.is_project is False
        assert m.is_macro is False
        assert m.is_macroset is False
        assert m.is_token is True
        m.assemble()
        assert os.path.exists('MTToken.rptok')
        os.remove('MTToken.rptok')

        m = GetAsset(fn)
        assert m.is_properties is False
        assert m.is_project is False
        assert m.is_macro is False
        assert m.is_macroset is False
        assert m.is_token is True
        m.assemble()
        assert os.path.exists('MTToken.rptok')
コード例 #2
0
 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')
コード例 #3
0
 def test_macro_assemble_macro2(self, tmpdir):
     saveplus = 'Minimum+Viable+Macro+2'
     m = GetAsset('macro/MVMacro2.xml')
     assert m is not None
     m.assemble()
     assert m.best_name_escaped() == saveplus
     assert os.path.exists(saveplus + '.mtmacro'), f'{saveplus+".mtmacro"} does not exist as expected'
コード例 #4
0
 def test_asset_project4_assemble(self, tmpdir):
     # project 4 has a macro2 and a text with a name
     m = GetAsset(self.source[3]['filename'])
     assert m is not None
     m.assemble()
     assert os.path.exists(self.source[3]['textfile']), f'{glob("*")=}\n\n{self.source=}'
     assert os.path.exists('Minimum+Viable+Macro+2.' + tagset.macro.ext)
コード例 #5
0
 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'
コード例 #6
0
 def test_asset_with_macro_command(self, tmpdir):
     fn = os.path.join(tmpdir, 'Junk.command')
     with open(fn, 'w') as f:
         f.write('')
     fn = os.path.join(tmpdir, 'Junk.xml')
     with open(fn, 'w') as f:
         f.write('<' + tagset.macro.tag + '>')
         f.write('  <label>Test</label>')
         f.write('</' + tagset.macro.tag + '>')
     m = GetAsset(fn)
     assert m.is_macro is True
     assert m.is_project is False
     assert m.is_macroset is False
     assert m.is_token is False
     assert m.is_properties is False
     m.assemble()
     assert os.path.exists('./Test.mtmacro')
     os.remove('./Test.mtmacro')
     m = GetAsset(os.path.join(tmpdir, 'Junk.command'))
     assert m.is_macro is True
     assert m.is_project is False
     assert m.is_macroset is False
     assert m.is_token is False
     assert m.is_properties is False
     m.assemble()
     assert os.path.exists('./Test.mtmacro')
     os.remove('./Test.mtmacro')
コード例 #7
0
 def test_asset_project1_assemble(self, tmpdir):
     print(f'in test_asset_project1_assemble with {self.source}')
     m = GetAsset(self.source[0]['filename'])
     assert m is not None
     m.assemble()
     assert os.path.exists('MVToken.' + tagset.token.ext)
     assert os.path.exists('MVProps.' + tagset.properties.ext)
     assert os.path.exists(self.source[0]['macrosetname'] + '.' + tagset.macroset.ext)
コード例 #8
0
ファイル: extract.py プロジェクト: mr-ice/maptool-macros
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()}'"
コード例 #9
0
 def test_macro_assemble_macro1(self, tmpdir):
     # saveperc = 'Minimum%20Viable%20Macro%201'
     # savepath = 'Minimum%2BViable%2BMacro%2B1'
     saveplus = 'Minimum+Viable+Macro+1'
     m = GetAsset('macro/MVMacro1.xml')
     assert m is not None
     m.assemble()
     assert m.best_name_escaped() == saveplus
     assert os.path.exists(saveplus + '.mtmacro'), f'{saveplus + ".mtmacro"} does not exist as expected'
コード例 #10
0
 def test_token_assemble_no_gmname_change(self, tmpdir):
     # TODO this will fail if MVToken ever gets a gmName
     tokenname = random_string()
     m = GetAsset('MVToken')
     assert m is not None
     m.assemble(tokenname)
     m = GetAsset(tokenname + '.' + tagset.token.ext)
     assert m is not None
     assert 'gmName' not in [x.tag for x in m.root.iterchildren()]
コード例 #11
0
 def test_asset_token_assemble_macroPropertiesMap(self, tmpdir):
     tokenname = 'MVToken'
     m = GetAsset(tokenname)
     assert m is not None
     m.assemble()
     n = GetAsset(tokenname + '.rptok')
     assert n is not None
     assert n.xml.find('macroPropertiesMap/entry/macro') is None
     assert n.xml.find('macroPropertiesMap/entry/' +
                       tagset.macro.tag) is not None
コード例 #12
0
 def test_asset_project3_assemble(self, tmpdir):
     # p3 has macroset, project
     # p2 has macro, text
     m = GetAsset(self.source[2]['filename'])
     assert m is not None
     m.assemble()
     assert os.path.exists(self.source[2]['macrosetname'] + '.' + tagset.macroset.ext), f'{glob("*")=}'
     # These files come from Project2
     assert os.path.exists('README.txt')
     assert os.path.exists('Minimum+Viable+Macro+1.' + tagset.macro.ext)
コード例 #13
0
 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
コード例 #14
0
 def test_asset_token_assemble(self, tmpdir):
     m = GetAsset('MVToken')
     assert m is not None
     assert m.fromdir is not None
     assert m.xmlfile is not None
     assert m.zipfile is None
     # assert False, f'{m.whence=}'
     # assert False, f'{m.dirname=}'
     m.assemble()
     assert os.path.exists('MVToken.rptok')
コード例 #15
0
 def test_asset_token_save_to(self, tmpdir):
     target = 'NewMVToken'
     targetAsset = GetAsset('MVToken')
     targetAsset.assemble()
     assert os.path.exists('MVToken.rptok')
     m = GetAsset('MVToken.rptok')
     assert m is not None
     # m.extract(save_name=target)
     assert m.output_dir == '.'
     assert m.save_to(target) == './' + target
コード例 #16
0
 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'
コード例 #17
0
 def test_token_assemble_sha_gmname(self, tmpdir):
     tokenname = 'Lib:' + random_string()
     tokennameq = tokenname.replace(':', '-')
     m = GetAsset('MVToken')
     assert m is not None
     m.root.name = objectify.StringElement(tokenname)
     m.assemble(tokennameq)
     m = GetAsset(MacroNameQuote(tokennameq + '.' + tagset.token.ext))
     assert m is not None
     assert 'gmName' in [x.tag for x in m.root.iterchildren()]
     assert m.root.gmName == git_tag_str
コード例 #18
0
 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("**/*")=}'
コード例 #19
0
 def test_token_extract_sha_gmname_remove(self, tmpdir):
     tokenname = 'Lib:' + random_string()
     tokennameq = tokenname.replace(':', '-')
     m = GetAsset('MVToken')
     assert m is not None
     m.assemble(save_name=tokennameq)
     m = GetAsset(tokennameq + '.' + tagset.token.ext)
     assert m is not None
     m.extract()
     assert os.path.exists(tokennameq)
     assert os.path.isdir(tokennameq)
     assert os.path.exists(os.path.join(tokennameq, 'content.xml'))
     xml = objectify.parse(os.path.join(tokennameq, 'content.xml'))
     assert 'gmName' not in [x.tag for x in xml.getroot().iterchildren()]
コード例 #20
0
ファイル: extract.py プロジェクト: mr-ice/maptool-macros
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()}\''
コード例 #21
0
 def test_asset_token_extract_with_name(self, tmpdir):
     tdir = 'MVToken'
     tfilename = tdir + '.rptok'
     target = 'NewMVToken'
     targetAsset = GetAsset(tdir)
     targetAsset.assemble()
     assert os.path.exists(tfilename), f'{tfilename} does not exist'
     m = GetAsset(tfilename)
     # assert False, m.save_to(None, target)
     assert m is not None
     assert m.fromdir is not None
     assert m.xmlfile is not None  # should this be None?
     assert m.zipfile is not None
     m.extract(save_name=target)
     for asset in 'properties.xml', 'content.xml', 'thumbnail', 'thumbnail_large', '1d20.command', '1d20.xml':
         assert os.path.exists(os.path.join(target, asset))
コード例 #22
0
 def test_asset_token_extract(self, tmpdir):
     tdir = 'MVToken'
     tfilename = tdir + '.rptok'
     # we don't come with a pre-assembled token, so assemble one
     targetAsset = GetAsset(tdir)
     targetAsset.assemble()
     assert os.path.exists(tfilename), f'{tfilename} does not exist'
     # The original is in 'MVToken', but the name is
     # 'MVToken+1' so we should have a copy there once extracted
     m = GetAsset(tfilename)
     m.extract()
     # assert False, m.save_to(None, target)
     assert m is not None
     assert m.fromdir is not None
     assert m.xmlfile is not None  # should this be None?
     assert m.zipfile is not None
     for asset in 'properties.xml', 'content.xml', 'thumbnail', 'thumbnail_large', '1d20.command', '1d20.xml':
         assert os.path.exists(os.path.join(tdir, asset))
コード例 #23
0
 def test_asset_with_distant_properties(self, tmpdir):
     os.chdir('/tmp')
     dn = os.path.join(tmpdir, 'MTProps')
     os.makedirs(dn, exist_ok=True)
     fn = os.path.join(dn, 'content.xml')
     log.info(f'creating empty properties at {fn}')
     with open(fn, 'w') as f:
         f.write('<' + tagset.properties.tag + '>')
         f.write('</' + tagset.properties.tag + '>')
     log.info(f'opening asset at {fn}')
     m = GetAsset(fn)
     assert m.is_properties is True
     assert m.is_project is False
     assert m.is_macro is False
     assert m.is_macroset is False
     assert m.is_token is False
     os.makedirs('output', exist_ok=True)
     m.assemble()
     assert os.path.exists('MTProps.mtprops')
     os.remove('MTProps.mtprops')
コード例 #24
0
 def setup_method(self, tmpdir):
     mvp = 'test/data/MinViable'
     for zf in glob(mvp + '/*.zip'):
         with zipfile.ZipFile(zf, 'r') as zip_ref:
             zip_ref.extractall(tmpdir)
     test_start_dir = os.getcwd()
     os.chdir(tmpdir)
     # Create a sample MVMacroSet.mtmacset for
     # the tests to use
     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)
     m.assemble(save_name='MVMacroSet')
     try:
         yield
     finally:
         os.chdir(test_start_dir)
コード例 #25
0
 def setup_method(self, tmpdir):
     mvp = 'test/data/MinViable'
     mvzips = ['MVMacro1.zip', 'MVMacro2.zip', 'MVProps.zip',
               'MVToken.zip']
     for zf in [os.path.join(mvp, z) for z in mvzips]:
         with zipfile.ZipFile(zf, 'r') as zip_ref:
             zip_ref.extractall(tmpdir)
     test_start_dir = os.getcwd()
     os.chdir(tmpdir)
     # Create a sample MVMacroSet.mtmacset for
     # the tests to use
     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)
     m.assemble(save_name='MVMacroSet')
     try:
         yield
     finally:
         os.chdir(test_start_dir)
コード例 #26
0
 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
コード例 #27
0
 def test_asset_token_extract_macro_dryrun(self, tmpdir):
     '''When extracting with dryrun, a token should not actually
     be created'''
     newname = random_string()
     macro_name = 'MVToken'
     m = GetAsset(macro_name)
     assert m is not None
     m.assemble(newname)
     n = GetAsset(newname + '.rptok')
     assert n is not None
     assert n.fromdir is not None
     assert n.xmlfile is not None
     assert n.zipfile is not None
     n.assemble(dryrun=True)
     assert not os.path.exists(os.path.join('.', newname))
     should_have = os.path.join('.', newname, 'properties.xml')
     assert not os.path.exists(
         should_have), f"{should_have} exists when using dryrun"
     macro_xml = os.path.join('.', newname, '1d20.xml')
     assert not os.path.exists(
         macro_xml), f"{macro_xml} exists when using dryrun"
     macro_cmd = os.path.join('.', newname, '1d20.command')
     assert not os.path.exists(
         macro_cmd), f"{macro_cmd} exists when using dryrun"
コード例 #28
0
ファイル: pypdb-header.py プロジェクト: mr-ice/maptool-macros
    def debug(self, message='', *args):
        print('DEBUG:', message.format(*args))

    def warn(self, message='', *args):
        print('WARN:', message.format(*args))

    def error(self, message='', *args):
        print('ERROR:', message.format(*args))


log = LogO()

#code.interact(local=locals())
tok = GetAsset('Lib-DND5e')
pdb.set_trace()
tok.assemble()


if __name__ == '__main__':
    AP = argparse.ArgumentParser()
    AP.add_argument('file',
                    default='test.xml',
                    help="initial project file to load")
    AP.add_argument('--out',
                    default='out.xml',
                    help='Output filename to use')

    args = AP.parse_args()

    q = objectify.parse(args.file).getroot()
    p = flatten_project(q)
コード例 #29
0
 def test_asset_project2_assemble(self, tmpdir):
     m = GetAsset(self.source[1]['filename'])
     assert m is not None
     m.assemble()
     assert os.path.exists('README.txt')
     assert os.path.exists('Minimum+Viable+Macro+1.' + tagset.macro.ext)
コード例 #30
0
 def test_asset_token_assemble_dryrun(self, tmpdir):
     macro_name = 'MVToken+1'
     m = GetAsset('MVToken')
     assert m is not None
     m.assemble(dryrun=True)
     assert not os.path.exists(macro_name + '.rptok')