Ejemplo n.º 1
0
    def test_bundle_no_deps(self):
        tempdir = tempfile.mkdtemp()

        try:
            zpm.create_project(tempdir, template='python')
            with open(os.path.join(tempdir, 'zapp.yaml')) as zapp_yaml:
                zapp = yaml.safe_load(zapp_yaml)

            # add some files to "bundling" section
            touch_file(tempdir, 'main.py')
            zapp['bundling'].append('main.py')

            # rewrite the zapp.yaml
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            zpm.bundle_project(tempdir)
            zapp_file = os.path.join(tempdir,
                                     os.path.basename(tempdir) + '.zapp')
            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
            ]
            assert expected_file_names == [x.name for x in tar.getmembers()]
        finally:
            shutil.rmtree(tempdir)
Ejemplo n.º 2
0
 def test_path_exists_not_dir(self):
     # A RuntimeError should be thrown if the target path exists and is
     # not a dir.
     _, tf = tempfile.mkstemp()
     with mock.patch('zpmlib.zpm._create_zapp_yaml') as czy:
         with pytest.raises(RuntimeError):
             zpm.create_project(tf)
         assert czy.call_count == 0
Ejemplo n.º 3
0
 def test_target_is_dir(self):
     # In this case, the target is a dir and it exists already.
     tempdir = tempfile.mkdtemp()
     try:
         with mock.patch('zpmlib.zpm._create_zapp_yaml') as czy:
             zpm.create_project(tempdir)
             assert czy.call_count == 1
     finally:
         shutil.rmtree(tempdir)
Ejemplo n.º 4
0
    def test_path_does_not_exist(self):
        # If the path does not exist, `create_project` should create the
        # directory (including intermediate directories) and bootstrap an empty
        # project.
        tempdir = tempfile.mkdtemp()
        target_dir = os.path.join(tempdir, 'foo', 'bar')

        try:
            with mock.patch('zpmlib.zpm._create_zapp_yaml') as czy:
                zpm.create_project(target_dir)
                assert czy.call_count == 1
        finally:
            shutil.rmtree(tempdir)
Ejemplo n.º 5
0
def new(args):
    """
    Create a default ZeroVM application ``zar.json`` specification in the
    target directory. If no directory is specified, ``zar.json`` will be
    created in the current directory.
    """

    try:
        zarjson = zpm.create_project(args.dir)
    except RuntimeError as err:
        print(err.message)
    else:
        print("Created '%s'" % zarjson)
Ejemplo n.º 6
0
def new(args):
    """Create template zapp.yaml file

    Create a default ZeroVM application zapp.yaml specification in the
    target directory. If no directory is specified, zapp.yaml will be
    created in the current directory.
    """

    try:
        zappyaml = zpm.create_project(args.dir)
    except RuntimeError as err:
        print(err)
    else:
        print("Created '%s'" % zappyaml)
Ejemplo n.º 7
0
def new(args):
    """Create template zapp.yaml file

    Create a default ZeroVM application zapp.yaml specification in the
    target directory. If no directory is specified, zapp.yaml will be
    created in the current directory.
    """

    try:
        project_files = zpm.create_project(args.dir,
                                           with_ui=args.with_ui,
                                           template=args.template)
    except Exception as err:
        print(err)
    else:
        for proj_file in project_files:
            print("Created '%s'" % proj_file)
Ejemplo n.º 8
0
def new(args):
    """Create template zapp.yaml file

    Create a default ZeroVM application zapp.yaml specification in the
    target directory. If no directory is specified, zapp.yaml will be
    created in the current directory.
    """

    try:
        project_files = zpm.create_project(
            args.dir,
            with_ui=args.with_ui,
            template=args.template)
    except Exception as err:
        print(err)
    else:
        for proj_file in project_files:
            print("Created '%s'" % proj_file)
Ejemplo n.º 9
0
    def test_bundle(self):
        tempdir = tempfile.mkdtemp()
        zapp_file = os.path.join(tempdir, os.path.basename(tempdir) + '.zapp')
        site_pkgs = os.path.join(tempdir, '.zapp/.zapp/venv/lib/python2.7/'
                                          'site-packages')
        try:
            zpm.create_project(tempdir, template='python')
            with open(os.path.join(tempdir, 'zapp.yaml')) as zapp_yaml:
                zapp = yaml.safe_load(zapp_yaml)

            # add some files to "bundling" section
            touch_file(tempdir, 'main.py')
            zapp['bundling'].append('main.py')

            # add dependencies:
            zapp['dependencies'] = [
                'dep1',
                'dep2',
                ['dontcare', 'foodep3'],
            ]

            # rewrite the zapp.yaml
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            ######################
            # Test normal bundling
            def tox_fetch_deps(*args, **kwargs):
                # fake creating a venv and installing deps with tox
                os.makedirs(site_pkgs)
                # add the deps: dep1.py (module) and dep2/ (package)
                touch_file(site_pkgs, 'dep1.py')
                os.makedirs(os.path.join(site_pkgs, 'dep2'))
                touch_file(os.path.join(site_pkgs, 'dep2'), '__init__.py')
                touch_file(os.path.join(site_pkgs, 'dep2'), 'foo.py')
                os.makedirs(os.path.join(site_pkgs, 'foodep3'))
                touch_file(os.path.join(site_pkgs, 'foodep3'), '__init__.py')
                touch_file(os.path.join(site_pkgs, 'foodep3'), 'foodep3.py')
                return 0

            with mock.patch('subprocess.Popen') as sppo:
                instance = sppo.return_value
                instance.wait.side_effect = tox_fetch_deps
                zpm.bundle_project(tempdir)
            # Test the deps file:
            with open(os.path.join(tempdir, '.zapp', 'deps.txt')) as deps_file:
                assert 'dep1\ndep2\ndontcare\n' == deps_file.read()
            # Test the subprocess call to tox:
            assert sppo.call_args[0][0] == [
                'tox', '-c', os.path.join(tempdir, '.zapp', 'tox.ini')
            ]
            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
                'lib/python2.7/site-packages/dep1.py',
                'lib/python2.7/site-packages/dep2',
                'lib/python2.7/site-packages/dep2/__init__.py',
                'lib/python2.7/site-packages/dep2/foo.py',
                'lib/python2.7/site-packages/foodep3',
                'lib/python2.7/site-packages/foodep3/__init__.py',
                'lib/python2.7/site-packages/foodep3/foodep3.py',
            ]
            assert sorted(expected_file_names) == sorted(
                [x.name for x in tar.getmembers()]
            )
            tar.close()

            ###################################
            # Test bundling with --refresh-deps
            # Different dependencies this time
            zapp['dependencies'] = ['dep1']
            with open(os.path.join(tempdir, 'zapp.yaml'), 'w') as zapp_yaml:
                zapp_yaml.write(yaml.dump(zapp))

            def tox_fetch_deps(*args, **kwargs):
                # fake creating a venv and installing deps with tox
                shutil.rmtree(site_pkgs)
                os.makedirs(site_pkgs)
                # add the deps: dep1.py (module) and dep2/ (package)
                touch_file(site_pkgs, 'dep1.py')
                return 0

            with mock.patch('subprocess.Popen') as sppo:
                instance = sppo.return_value
                instance.wait.side_effect = tox_fetch_deps
                zpm.bundle_project(tempdir, refresh_deps=True)

            assert sppo.call_args[0][0] == [
                'tox', '-r', '-c', os.path.join(tempdir, '.zapp', 'tox.ini')
            ]

            tar = tarfile.open(zapp_file)
            expected_file_names = [
                'boot/system.map',
                'zapp.yaml',
                'main.py',
                'lib/python2.7/site-packages/dep1.py',
            ]
            assert sorted(expected_file_names) == sorted(
                [x.name for x in tar.getmembers()]
            )
            tar.close()
        finally:
            shutil.rmtree(tempdir)