def test_init_dict(): d = {'foo': 'bar'} tree = OrderedTree('.', **d) print_yaml("tree init using a dict", tree) assert 'foo' in tree assert tree['foo'] == 'bar' d2 = {'foo': {'bar': 'baz'}} tree = OrderedTree('.', **d2) print_yaml("tree init using a complex dict", tree) assert 'foo.bar' in tree assert tree['foo.bar'] == 'baz' import configure x = configure.Configuration({'foo': 'bar'}) assert is_dict(x)
def test_lookup_non_existing_key(our_cwd_setup, lookup_style): import cli.yamls from cli.exceptions import IRKeyNotFoundException tester_file_name = 'lookup_%s_style_non_existing_key.yml' % lookup_style tester_file = os.path.join(utils.TESTS_CWD, tester_file_name) # load settings from yaml and set them into Lookup 'settings' class var cli.yamls.Lookup.settings = configure.Configuration().from_file( tester_file).configure() if lookup_style == 'new': # explicitly call 'in_string_lookup' in order to create Lookup objects cli.yamls.Lookup.in_string_lookup() # dump the settings with the non-existing key and expecting # IRKeyNotFoundException to be raised with pytest.raises(IRKeyNotFoundException): yaml.safe_dump(cli.yamls.Lookup.settings, default_flow_style=False)
def test_circular_reference_lookup(): import cli.yamls tester_file_name = 'lookup_new_style_circular_reference.yml' tester_file = os.path.join(utils.TESTS_CWD, tester_file_name) # load settings from yaml and set them into Lookup 'settings' class var cli.yamls.Lookup.settings = configure.Configuration().from_file( tester_file).configure() # cli.yamls.Lookup.handling_nested_lookups = False cli.yamls.Lookup.in_string_lookup() # dump the settings in order to retrieve the key's value and load them # again for value validation with pytest.raises(exceptions.IRInfiniteLookupException): yaml.safe_load( yaml.safe_dump(cli.yamls.Lookup.settings, default_flow_style=False))
def test_lookup(our_cwd_setup, lookup_style): import cli.yamls tester_file_name = 'lookup_%s_style.yml' % lookup_style tester_file = os.path.join(utils.TESTS_CWD, tester_file_name) # load settings from yaml and set them into Lookup 'settings' class var cli.yamls.Lookup.settings = configure.Configuration().from_file( tester_file).configure() if lookup_style == 'new': # explicitly call 'in_string_lookup' in order to create Lookup objects cli.yamls.Lookup.in_string_lookup() # dump the settings in order to retrieve the key's value and load them # again for value validation settings = yaml.safe_load( yaml.safe_dump(cli.yamls.Lookup.settings, default_flow_style=False)) assert settings['foo']['key_to_be_found'] == "key was found"
def build_core(iface, directory, commands): global BLACKLIST_DIRS global BLACKLIST_FILES config = configure.Configuration(directory) if config.package is None: iface.fail("Run configure before attempting to build the app.") if not config.include_sqlite: BLACKLIST_DIRS += ['sqlite3'] BLACKLIST_FILES += ['_sqlite3.so'] shelve_lib('libsqlite3.so') if not config.include_pil: BLACKLIST_DIRS += ['PIL'] BLACKLIST_FILES += ['_imaging.so', '_imagingft.so', '_imagingmath.so'] if RENPY: manifest_extra = '<uses-feature android:glEsVersion="0x00020000" />' default_icon = "templates/renpy-icon.png" default_presplash = "templates/renpy-presplash.jpg" public_dir = None private_dir = None assets_dir = directory else: manifest_extra = "" default_icon = "templates/pygame-icon.png" default_presplash = "templates/pygame-presplash.jpg" if config.layout == "internal": private_dir = directory public_dir = None assets_dir = None elif config.layout == "external": private_dir = None public_dir = directory assets_dir = None elif config.layout == "split": private_dir = join_and_check(directory, "internal") public_dir = join_and_check(directory, "external") assets_dir = join_and_check(directory, "assets") versioned_name = config.name.replace(" ", "").replace( "'", "") + "-" + config.version # Annoying fixups. config.name = config.name.replace("'", "\\'") config.icon_name = config.icon_name.replace("'", "\\'") # Figure out versions of the private and public data. private_version = str(time.time()) if public_dir: public_version = private_version else: public_version = None # Render the various templates into control files. render( "AndroidManifest.tmpl.xml", "AndroidManifest.xml", config=config, manifest_extra=manifest_extra, ) render("strings.xml", "res/values/strings.xml", public_version=public_version, private_version=private_version, config=config) try: os.unlink("build.xml") except: pass iface.info("Updating build files.") # Update the project to a recent version. subprocess.call([ plat.android, "update", "project", "-p", '.', '-t', 'android-8', '-n', versioned_name ]) iface.info("Creating assets directory.") shutil.rmtree("assets") if assets_dir is not None: shutil.copytree(assets_dir, "assets") else: os.mkdir("assets") # Copy in the Ren'Py common assets. if os.path.exists("engine-assets/common"): shutil.copytree("engine-assets/common", "assets/common") # Ren'Py uses a lot of names that don't work as assets. Auto-rename # them. for dirpath, dirnames, filenames in os.walk("assets", topdown=False): for fn in filenames + dirnames: if fn[0] == ".": continue old = os.path.join(dirpath, fn) new = os.path.join(dirpath, "x-" + fn) os.rename(old, new) iface.info("Packaging internal data.") private_dirs = ['private'] if private_dir is not None: private_dirs.append(private_dir) if os.path.exists("engine-private"): private_dirs.append("engine-private") make_tar("assets/private.mp3", private_dirs) if public_dir is not None: iface.info("Packaging external data.") make_tar("assets/public.mp3", [public_dir]) # Copy over the icon and presplash files. shutil.copy( join_and_check(directory, "android-icon.png") or default_icon, "res/drawable/icon.png") shutil.copy( join_and_check(directory, "android-presplash.jpg") or default_presplash, "res/drawable/presplash.jpg") # Build. iface.info("I'm using Ant to build the package.") # Clean is required try: subprocess.check_call([plat.ant, "clean"] + commands) iface.success("It looks like the build succeeded.") except: iface.fail("The build seems to have failed.")
def build(iface, directory, commands): # Are we doing a Ren'Py build? global RENPY RENPY = os.path.exists("renpy") if not os.path.isdir(directory): iface.fail("{} is not a directory.".format(directory)) if RENPY and not os.path.isdir(os.path.join(directory, "game")): iface.fail("{} does not contain a Ren'Py game.".format(directory)) config = configure.Configuration(directory) if config.package is None: iface.fail("Run configure before attempting to build the app.") global blacklist global whitelist blacklist = PatternList("blacklist.txt") whitelist = PatternList("whitelist.txt") if RENPY: manifest_extra = None default_icon = "templates/renpy-icon.png" default_icon_fg = "templates/pygame-icon-foreground.png" default_icon_bg = "templates/pygame-icon-background.png" default_presplash = "templates/renpy-presplash.jpg" public_dir = None private_dir = None assets_dir = directory else: manifest_extra = "" default_icon = "templates/pygame-icon.png" default_icon_fg = "templates/pygame-icon-foreground.png" default_icon_bg = "templates/pygame-icon-background.png" default_presplash = "templates/pygame-presplash.jpg" if config.layout == "internal": private_dir = directory public_dir = None assets_dir = None elif config.layout == "external": private_dir = None public_dir = directory assets_dir = None elif config.layout == "split": private_dir = join_and_check(directory, "internal") public_dir = join_and_check(directory, "external") assets_dir = join_and_check(directory, "assets") versioned_name = config.name.replace(" ", "").replace("'", "") + "-" + config.version # Annoying fixups. config.name = config.name.replace("'", "\\'") config.icon_name = config.icon_name.replace("'", "\\'") # Figure out versions of the private and public data. private_version = str(time.time()) if public_dir: public_version = private_version else: public_version = None # Render the various templates into control files. render( "AndroidManifest.tmpl.xml", "AndroidManifest.xml", config = config, manifest_extra = manifest_extra, ) render( "strings.xml", "res/values/strings.xml", public_version = public_version, private_version = private_version, config = config) try: os.unlink("build.xml") except: pass iface.info("Updating source code.") #edit_file("src/org/renpy/android/DownloaderActivity.java", r'import .*\.R;', 'import {}.R;'.format(config.package)) #edit! iface.info("Updating build files.") # Update the project to a recent version. subprocess.call([plat.android, "update", "project", "-p", '.', '-t', 'android-28', '-n', versioned_name, # "--library", "android-sdk/extras/google/play_licensing/library", #"--library", "android-sdk/extras/google/play_apk_expansion/downloader_library", ]) iface.info("Creating assets directory.") if os.path.isdir("assets"): shutil.rmtree("assets") if assets_dir is not None: make_tree(assets_dir, "assets") else: os.mkdir("assets") # Copy in the Ren'Py common assets. if os.path.exists("renpy/common"): if os.path.isdir("assets/common"): shutil.rmtree("assets/common") make_tree("renpy/common", "assets/common") # Ren'Py uses a lot of names that don't work as assets. Auto-rename # them. for dirpath, dirnames, filenames in os.walk("assets", topdown=False): for fn in filenames + dirnames: if fn[0] == ".": continue old = os.path.join(dirpath, fn) new = os.path.join(dirpath, "x-" + fn) os.rename(old, new) if config.expansion: iface.info("Creating expansion file.") expansion_file = "main.{}.{}.obb".format(config.numeric_version, config.package) zf = zipfile.ZipFile(expansion_file, "w", zipfile.ZIP_STORED) zip_directory(zf, "assets") zf.close() # Delete and re-make the assets directory. shutil.rmtree("assets") os.mkdir("assets") # Write the file size into DownloaderActivity. file_size = os.path.getsize(expansion_file) edit_file("src/org/renpy/android/DownloaderActivity.java", r' private int fileVersion =', ' private int fileVersion = {};'.format(config.numeric_version)) edit_file("src/org/renpy/android/DownloaderActivity.java", r' private int fileSize =', ' private int fileSize = {};'.format(file_size)) else: expansion_file = None iface.info("Packaging internal data.") private_dirs = [ 'private' ] if private_dir is not None: private_dirs.append(private_dir) if os.path.exists("engine-private"): private_dirs.append("engine-private") make_tar("assets/private.mp3", private_dirs) if public_dir is not None: iface.info("Packaging external data.") make_tar("assets/public.mp3", [ public_dir ]) # Copy over the icon and presplash files. shutil.copy(join_and_check(directory, "android-icon.png") or default_icon, "res/mipmap/ic_launcher.png") shutil.copy(join_and_check(directory, "android-icon-foreground.png") or default_icon_fg, "res/drawable/ic_foreground_trimmed.png") shutil.copy(join_and_check(directory, "android-icon-background.png") or default_icon_bg, "res/drawable/ic_background.png") shutil.copy(join_and_check(directory, "android-presplash.jpg") or default_presplash, "res/drawable/presplash.jpg") # Build. iface.info("I'm using Ant to build the package.") # Clean is required try: subprocess.check_call([plat.ant, "clean"] + commands) iface.success("It looks like the build succeeded.") except: iface.fail("The build seems to have failed.") if (expansion_file is not None) and ("install" in commands): iface.info("Uploading expansion file.") dest = "/mnt/sdcard/{}".format(expansion_file) subprocess.check_call([ plat.adb, "push", expansion_file, dest ]) iface.success("Uploaded the expansion file.") if expansion_file is not None: os.rename(expansion_file, "bin/" + expansion_file) if ("install" in commands): iface.info("Launching app.") launch_activity = "PythonActivity" subprocess.check_call([ plat.adb, "shell", "am", "start", "-W", "-a", "android.intent.action.MAIN", "{}/org.renpy.android.{}".format(config.package, launch_activity), ])
def test_is_dict(): import configure x = configure.Configuration({'foo': 'bar'}) assert is_dict(x)