Exemplo n.º 1
0
    def test_targetAppConfigMerge(self):
        test_dir = self.writeTestFiles(Test_Target_Config_Merge_App, True)

        os.chdir(test_dir)
        c = validate.currentDirectoryModule()
        target, errors = c.satisfyTarget("bar,")
        merged_config = target.getMergedConfig()

        self.assertIn("foo", merged_config)
        self.assertIn("bar", merged_config)
        self.assertIn("new", merged_config)
        self.assertIn("a", merged_config["foo"])
        self.assertIn("b", merged_config["foo"])
        self.assertIn("c", merged_config["foo"])
        self.assertEqual(merged_config["foo"]["a"], 321)
        self.assertEqual(merged_config["foo"]["b"], 456)
        self.assertEqual(merged_config["foo"]["c"], 112233)
        self.assertIn("bar", merged_config)
        self.assertIn("d", merged_config["bar"])
        self.assertEqual(merged_config["bar"]["d"], "ghi")
        self.assertIn("new", merged_config)
        self.assertEqual(merged_config["new"], 123)

        os.chdir(self.restore_cwd)
        rmRf(test_dir)
Exemplo n.º 2
0
    def test_buildTrivialExe(self):
        test_dir = self.writeTestFiles(Test_Trivial_Exe)

        stdout = self.runCheckCommand(
            ['--target', systemDefaultTarget(), 'build'], test_dir)

        rmRf(test_dir)
Exemplo n.º 3
0
def execCommand(args, following_args):
    if args.link_target:
        c = validate.currentDirectoryModule()
        if not c:
            return 1
        err = validate.targetNameValidationError(args.link_target)
        if err:
            logging.error(err)
            return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_targets'))
        src = os.path.join(folders.globalTargetInstallDirectory(), args.link_target)
        dst = os.path.join(os.getcwd(), 'yotta_targets', args.link_target)
        # if the target is already installed, rm it
        fsutils.rmRf(dst)
    else:
        t = validate.currentDirectoryTarget()
        if not t:
            return 1
        fsutils.mkDirP(folders.globalTargetInstallDirectory())
        src = os.getcwd()
        dst = os.path.join(folders.globalTargetInstallDirectory(), t.getName())

    if args.link_target:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
    else:
        logging.info('%s -> %s' % (dst, src))
    fsutils.symlink(src, dst)
Exemplo n.º 4
0
    def test_buildComplexSpaceInPath(self):
        test_dir = self.writeTestFiles(Test_Complex, True)

        stdout = self.runCheckCommand(
            ['--target', systemDefaultTarget(), 'build'], test_dir)

        rmRf(test_dir)
Exemplo n.º 5
0
    def test_targetAppConfigMerge(self):
        test_dir = self.writeTestFiles(Test_Target_Config_Merge_App, True)

        os.chdir(test_dir)
        c = validate.currentDirectoryModule()
        target, errors = c.satisfyTarget('bar,')
        merged_config = target.getMergedConfig()

        self.assertIn("foo", merged_config)
        self.assertIn("bar", merged_config)
        self.assertIn("new", merged_config)
        self.assertIn("a", merged_config['foo'])
        self.assertIn("b", merged_config['foo'])
        self.assertIn("c", merged_config['foo'])
        self.assertEqual(merged_config['foo']['a'], 321)
        self.assertEqual(merged_config['foo']['b'], 456)
        self.assertEqual(merged_config['foo']['c'], 112233)
        self.assertIn("bar", merged_config)
        self.assertIn("d", merged_config['bar'])
        self.assertEqual(merged_config['bar']['d'], "ghi")
        self.assertIn("new", merged_config)
        self.assertEqual(merged_config['new'], 123)

        os.chdir(self.restore_cwd)
        rmRf(test_dir)
Exemplo n.º 6
0
    def test_installDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install'],
                                      test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls'],
                                      test_dir)
        self.assertIn('testmod', stdout)
        self.assertIn('other-testing-dummy', stdout)
        self.assertIn('test-testing-dummy', stdout)
        self.assertIn('test-target-dep', stdout)

        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'],
                                      test_dir)
        self.assertIn('testmod', stdout)
        self.assertIn('other-testing-dummy', stdout)
        self.assertIn('test-testing-dummy', stdout)
        self.assertIn('test-target-dep', stdout)

        # and test install <modulename>
        stdout = self.runCheckCommand(
            ['--target', Test_Target, 'install', 'hg-access-testing'],
            test_dir)
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls'],
                                      test_dir)
        self.assertIn('hg-access-testing', stdout)
        rmRf(test_dir)
Exemplo n.º 7
0
    def test_installAllComplexTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Complex_Module_JSON)
        stdout = self.runCheckCommand(
            ['--target', Test_Target, 'install', '--test-dependencies', 'all'],
            test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'],
                                      test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-g', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertIn('test-testdep-i', stdout)
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)
        self.assertNotIn('missing', stdout)

        rmRf(test_dir)
Exemplo n.º 8
0
def satisfyVersionFromSearchPaths(name, version_required, search_paths, update=False, type='module', inherit_shrinkwrap=None):
    ''' returns a Component/Target for the specified version, if found in the
        list of search paths. If `update' is True, then also check for newer
        versions of the found component, and update it in-place (unless it was
        installed via a symlink).
    '''
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack

    v = None
    try:
        sv = sourceparse.parseSourceURL(version_required)
    except ValueError as e:
        logging.error(e)
        return None

    try:
        local_version = searchPathsFor(
            name,
            sv.semanticSpec(),
            search_paths,
            type,
            inherit_shrinkwrap = inherit_shrinkwrap
        )
    except pack.InvalidDescription as e:
        logger.error(e)
        return None

    logger.debug("%s %s locally" % (('found', 'not found')[not local_version], name))
    if local_version:
        if update and not local_version.installedLinked():
            #logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
            v = latestSuitableVersion(name, version_required, registry=_registryNamespaceForType(type))
            if local_version:
                local_version.setLatestAvailable(v)

        # if we don't need to update, then we're done
        if local_version.installedLinked() or not local_version.outdated():
            logger.debug("satisfy component from directory: %s" % local_version.path)
            # if a component exists (has a valid description file), and either is
            # not outdated, or we are not updating
            if name != local_version.getName():
                raise Exception('Component %s found in incorrectly named directory %s (%s)' % (
                    local_version.getName(), name, local_version.path
                ))
            return local_version

        # otherwise, we need to update the installed component
        logger.info('update outdated: %s@%s -> %s' % (
            name,
            local_version.getVersion(),
            v
        ))
        # must rm the old component before continuing
        fsutils.rmRf(local_version.path)
        return _satisfyVersionByInstallingVersion(
            name, version_required, local_version.path, v, type=type, inherit_shrinkwrap=inherit_shrinkwrap
        )
    return None
Exemplo n.º 9
0
    def test_updateExplicit(self):
        path = self.writeTestFiles(Test_Outdated, True)

        stdout, stderr, statuscode = cli.run(['-t', 'x86-linux-native', 'update', 'test-testing-dummy'], cwd=path)
        self.assertEqual(statuscode, 0)
        self.assertIn('download test-testing-dummy', stdout + stderr)

        rmRf(path)
Exemplo n.º 10
0
 def test_testOutputFilterNotFound(self):
     test_dir = self.writeTestFiles(Test_Fitler_NotFound, True)
     stdout, stderr, statuscode = cli.run(['--target', systemDefaultTarget(), 'test'], cwd=test_dir)
     if statuscode == 0:
         print(stdout)
         print(stderr)
     self.assertNotEqual(statuscode, 0)
     rmRf(test_dir)
Exemplo n.º 11
0
 def tearDownClass(cls):
     rmRf(cls.test_dir)
     cls.test_dir = None
     if cls.saved_settings_dir is not None:
         os.environ['YOTTA_USER_SETTINGS_DIR'] = cls.saved_settings_dir
         cls.saved_settings_dir = None
     else:
         del os.environ['YOTTA_USER_SETTINGS_DIR']
Exemplo n.º 12
0
    def test_outdated(self):
        path = self.writeTestFiles(Test_Outdated, True)
        
        stdout, stderr, statuscode = cli.run(['-t', 'x86-linux-native', 'outdated'], cwd=path)
        self.assertNotEqual(statuscode, 0)
        self.assertIn('test-testing-dummy', stdout + stderr)

        rmRf(path)
Exemplo n.º 13
0
 def tearDownClass(cls):
     rmRf(cls.test_dir)
     cls.test_dir = None
     if cls.saved_settings_dir is not None:
         os.environ['YOTTA_USER_SETTINGS_DIR'] = cls.saved_settings_dir
         cls.saved_settings_dir = None
     else:
         del os.environ['YOTTA_USER_SETTINGS_DIR']
Exemplo n.º 14
0
def rmLinkOrDirectory(path, nonexistent_warning):
    if not os.path.exists(path):
        logging.warning(nonexistent_warning)
        return 1
    if fsutils.isLink(path):
        fsutils.rmF(path)
    else:
        fsutils.rmRf(path)
    return 0
Exemplo n.º 15
0
 def test_tests(self):
     test_dir = self.writeTestFiles(Test_Tests, True)
     output = self.runCheckCommand(['--target', systemDefaultTarget(), 'build'], test_dir)
     output = self.runCheckCommand(['--target', systemDefaultTarget(), 'test'], test_dir)
     self.assertIn('test-a passed', output)
     self.assertIn('test-c passed', output)
     self.assertIn('test-d passed', output)
     self.assertIn('test-e passed', output)
     self.assertIn('test-f passed', output)
     self.assertIn('test-g passed', output)
     rmRf(test_dir)
Exemplo n.º 16
0
 def test_buildTests(self):
     test_dir = self.writeTestFiles(Test_Tests, True)
     stdout = self.runCheckCommand(['--target', systemDefaultTarget(), 'build'], test_dir)
     stdout = self.runCheckCommand(['--target', systemDefaultTarget(), 'test'], test_dir)
     self.assertIn('test-a', stdout)
     self.assertIn('test-c', stdout)
     self.assertIn('test-d', stdout)
     self.assertIn('test-e', stdout)
     self.assertIn('test-f', stdout)
     self.assertIn('test-g', stdout)
     rmRf(test_dir)
Exemplo n.º 17
0
    def unpackInto(self, directory):
        logger.debug('unpack version %s from hg repo %s to %s' % (self.version, self.working_copy.directory, directory))
        if self.isTip():
            tag = None
        else:
            tag = self.tag
        fsutils.rmRf(directory)
        vcs.HG.cloneToDirectory(self.working_copy.directory, directory, tag)

        # remove temporary files created by the HGWorkingCopy clone
        self.working_copy.remove()
Exemplo n.º 18
0
    def test_uninstallNonExistent(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir)
        self.assertTrue(os.path.exists(os.path.join(test_dir, 'yotta_modules', 'testing-dummy')))

        stdout, stderr, statuscode = cli.run(['uninstall', 'nonexistent'], cwd=test_dir)
        self.assertNotEqual(statuscode, 0)

        rmRf(test_dir)
Exemplo n.º 19
0
 def test_setTarget(self):
     rmRf(os.path.join(self.test_dir, '.yotta.json'))
     stdout = self.runCheckCommand(['target', 'testtarget', '-g'])
     stdout = self.runCheckCommand(['target'])
     self.assertTrue(stdout.find('testtarget') != -1)
     stdout = self.runCheckCommand(['target', 'x86-linux-native', '-g'])
     if os.name == 'posix':
         # check that the settings file was created with the right permissions
         self.assertFalse(
             os.stat(os.path.join(os.path.expanduser('~'), '.yotta', 'config.json')).st_mode & Check_Not_Stat
         )
Exemplo n.º 20
0
    def unpackInto(self, directory):
        # vcs, , represent version controlled directories, internal
        from yotta.lib import vcs
        # fsutils, , misc filesystem utils, internal
        from yotta.lib import fsutils
        logger.debug('unpack version %s from git repo %s to %s' % (self.version, self.working_copy.directory, directory))
        tag = self.tag
        fsutils.rmRf(directory)
        vcs.Git.cloneToDirectory(self.working_copy.directory, directory, tag)

        # remove temporary files created by the GitWorkingCopy clone
        self.working_copy.remove()
Exemplo n.º 21
0
    def test_moduleConfigIgnored(self):
        test_dir = self.writeTestFiles(Test_Module_Config_Ignored, True)

        os.chdir(test_dir)
        c = validate.currentDirectoryModule()
        target, errors = c.satisfyTarget('bar,')
        merged_config = target.getMergedConfig()

        self.assertNotIn("new", merged_config)

        os.chdir(self.restore_cwd)
        rmRf(test_dir)
Exemplo n.º 22
0
 def test_setTarget(self):
     rmRf(os.path.join(self.test_dir, '.yotta.json'))
     stdout = self.runCheckCommand(['target', 'testtarget', '-g', '-n'])
     stdout = self.runCheckCommand(['target'])
     self.assertTrue(stdout.find('testtarget') != -1)
     stdout = self.runCheckCommand(['target', 'x86-linux-native', '-g'])
     if os.name == 'posix':
         # check that the settings file was created with the right permissions
         self.assertFalse(
             os.stat(
                 os.path.join(os.path.expanduser('~'), '.yotta',
                              'config.json')).st_mode & Check_Not_Stat)
Exemplo n.º 23
0
    def unpackInto(self, directory):
        # vcs, , represent version controlled directories, internal
        from yotta.lib import vcs
        # fsutils, , misc filesystem utils, internal
        from yotta.lib import fsutils
        logger.debug('unpack version %s from git repo %s to %s' % (self.version, self.working_copy.directory, directory))
        tag = self.tag
        fsutils.rmRf(directory)
        vcs.Git.cloneToDirectory(self.working_copy.directory, directory, tag)

        # remove temporary files created by the GitWorkingCopy clone
        self.working_copy.remove()
Exemplo n.º 24
0
    def test_moduleConfigIgnored(self):
        test_dir = self.writeTestFiles(Test_Module_Config_Ignored, True)

        os.chdir(test_dir)
        c = validate.currentDirectoryModule()
        target, errors = c.satisfyTarget("bar,")
        merged_config = target.getMergedConfig()

        self.assertNotIn("new", merged_config)

        os.chdir(self.restore_cwd)
        rmRf(test_dir)
Exemplo n.º 25
0
 def test_buildTests(self):
     test_dir = self.writeTestFiles(Test_Tests, True)
     stdout = self.runCheckCommand(
         ['--target', systemDefaultTarget(), 'build'], test_dir)
     stdout = self.runCheckCommand(
         ['--target', systemDefaultTarget(), 'test'], test_dir)
     self.assertIn('test-a', stdout)
     self.assertIn('test-c', stdout)
     self.assertIn('test-d', stdout)
     self.assertIn('test-e', stdout)
     self.assertIn('test-f', stdout)
     self.assertIn('test-g', stdout)
     rmRf(test_dir)
Exemplo n.º 26
0
 def test_testOutputFilterFailing(self):
     test_dir = self.writeTestFiles(Test_Fitler_Fail, True)
     stdout, stderr, statuscode = cli.run(['--target', systemDefaultTarget(), 'test'], cwd=test_dir)
     if statuscode == 0:
         print(stdout)
         print(stderr)
     self.assertIn('test-a failed', '%s %s' % (stdout, stderr))
     self.assertIn('test-c failed', '%s %s' % (stdout, stderr))
     self.assertIn('test-d failed', '%s %s' % (stdout, stderr))
     self.assertIn('test-e failed', '%s %s' % (stdout, stderr))
     self.assertIn('test-f failed', '%s %s' % (stdout, stderr))
     self.assertIn('test-g failed', '%s %s' % (stdout, stderr))
     self.assertNotEqual(statuscode, 0)
     rmRf(test_dir)
Exemplo n.º 27
0
    def test_uninstall(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install'], test_dir)
        self.assertTrue(os.path.exists(os.path.join(test_dir, 'yotta_modules', 'testing-dummy')))

        self.runCheckCommand(['uninstall', 'testing-dummy'], test_dir)
        self.assertFalse(os.path.exists(os.path.join(test_dir, 'yotta_modules', 'testing-dummy')))

        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir)
        self.assertNotIn(' testing-dummy', stdout)

        rmRf(test_dir)
Exemplo n.º 28
0
    def test_installAllTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install', '--test-dependencies', 'all'], test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir)
        self.assertIn('testmod', stdout)
        self.assertIn('other-testing-dummy', stdout)
        self.assertIn('test-testing-dummy', stdout)
        self.assertIn('test-target-dep', stdout)
        self.assertNotIn('missing', stdout)
        rmRf(test_dir)
Exemplo n.º 29
0
def unpackFrom(tar_file_path, to_directory):
    # first unpack into a sibling directory of the specified directory, and
    # then move it into place.

    # we expect our tarballs to contain a single top-level directory. We strip
    # off this name as we extract to minimise the path length

    into_parent_dir = os.path.dirname(to_directory)
    fsutils.mkDirP(into_parent_dir)
    temp_directory = tempfile.mkdtemp(dir=into_parent_dir)
    try:
        with tarfile.open(tar_file_path) as tf:
            strip_dirname = ''
            # get the extraction directory name from the first part of the
            # extraction paths: it should be the same for all members of
            # the archive
            for m in tf.getmembers():
                split_path = fsutils.fullySplitPath(m.name)
                logger.debug('process member: %s %s', m.name, split_path)
                if os.path.isabs(m.name) or '..' in split_path:
                    raise ValueError('archive uses invalid paths')
                if not strip_dirname:
                    if len(split_path) != 1 or not len(split_path[0]):
                        raise ValueError(
                            'archive does not appear to contain a single module'
                        )
                    strip_dirname = split_path[0]
                    continue
                else:
                    if split_path[0] != strip_dirname:
                        raise ValueError(
                            'archive does not appear to contain a single module'
                        )
                m.name = os.path.join(*split_path[1:])
                tf.extract(m, path=temp_directory)
        # make sure the destination directory doesn't exist:
        fsutils.rmRf(to_directory)
        shutil.move(temp_directory, to_directory)
        temp_directory = None
        logger.debug('extraction complete %s', to_directory)
    except IOError as e:
        if e.errno != errno.ENOENT:
            logger.error('failed to extract tarfile %s', e)
            fsutils.rmF(tar_file_path)
        raise
    finally:
        if temp_directory is not None:
            # if anything has failed, cleanup
            fsutils.rmRf(temp_directory)
Exemplo n.º 30
0
    def test_default_ignores(self):
        default_test_dir = writeTestFiles(Default_Test_Files)
        c = component.Component(default_test_dir)
        self.assertTrue(c.ignores('.something.c.swp'))
        self.assertTrue(c.ignores('.something.c~'))
        self.assertTrue(c.ignores('path/to/.something.c.swm'))
        self.assertTrue(c.ignores('path/to/.something.c~'))
        self.assertTrue(c.ignores('.DS_Store'))
        self.assertTrue(c.ignores('.git'))
        self.assertTrue(c.ignores('.hg'))
        self.assertTrue(c.ignores('.svn'))
        self.assertTrue(c.ignores('yotta_modules'))
        self.assertTrue(c.ignores('yotta_targets'))
        self.assertTrue(c.ignores('build'))
        self.assertTrue(c.ignores('.yotta.json'))

        rmRf(default_test_dir)
Exemplo n.º 31
0
def unpackFrom(tar_file_path, to_directory):
    # first unpack into a sibling directory of the specified directory, and
    # then move it into place.

    # we expect our tarballs to contain a single top-level directory. We strip
    # off this name as we extract to minimise the path length

    into_parent_dir = os.path.dirname(to_directory)
    fsutils.mkDirP(into_parent_dir)
    temp_directory = tempfile.mkdtemp(dir=into_parent_dir)
    try:
        with tarfile.open(tar_file_path) as tf:
            strip_dirname = ''
            # get the extraction directory name from the first part of the
            # extraction paths: it should be the same for all members of
            # the archive
            for m in tf.getmembers():
                split_path = fsutils.fullySplitPath(m.name)
                logger.debug('process member: %s %s', m.name, split_path)
                if os.path.isabs(m.name) or '..' in split_path:
                    raise ValueError('archive uses invalid paths')
                if not strip_dirname:
                    if len(split_path) != 1 or not len(split_path[0]):
                        raise ValueError('archive does not appear to contain a single module')
                    strip_dirname = split_path[0]
                    continue
                else:
                    if split_path[0] != strip_dirname:
                        raise ValueError('archive does not appear to contain a single module')
                m.name = os.path.join(*split_path[1:])
                tf.extract(m, path=temp_directory)
        # make sure the destination directory doesn't exist:
        fsutils.rmRf(to_directory)
        shutil.move(temp_directory, to_directory)
        temp_directory = None
        logger.debug('extraction complete %s', to_directory)
    except IOError as e:
        if e.errno != errno.ENOENT:
            logger.error('failed to extract tarfile %s', e)
            fsutils.rmF(tar_file_path)
        raise
    finally:
        if temp_directory is not None:
            # if anything has failed, cleanup
            fsutils.rmRf(temp_directory)
Exemplo n.º 32
0
def execCommand(args, following_args):
    err = validate.componentNameValidationError(args.component)
    if err:
        logging.error(err)
        return 1
    c = validate.currentDirectoryModule()
    if not c:
        return 1
    status = 0
    if not c.removeDependency(args.component):
        status = 1
    else:
        c.writeDescription()
    path = os.path.join(c.modulesPath(), args.component)
    if fsutils.isLink(path):
        fsutils.rmF(path)
    else:
        fsutils.rmRf(path)
    return status
Exemplo n.º 33
0
def execCommand(args, following_args):
    err = validate.componentNameValidationError(args.component)
    if err:
        logging.error(err)
        return 1
    c = validate.currentDirectoryModule()
    if not c:
        return 1
    status = 0
    if not c.removeDependency(args.component):
        status = 1
    else:
        c.writeDescription()
    path = os.path.join(c.modulesPath(), args.component)
    if fsutils.isLink(path):
        fsutils.rmF(path)
    else:
        fsutils.rmRf(path)
    return status
Exemplo n.º 34
0
    def test_installNoComplexTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Complex_Module_JSON)
        stdout = self.runCheckCommand([
            '--target', Test_Target, 'install', '--test-dependencies', 'none'
        ], test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls'],
                                      test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        # e should be installed because it is both a test dep and non-test dep:
        # maybe it shouldn't show up in the listing without -a though?
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertNotIn('test-testdep-g', stdout)
        self.assertNotIn('test-testdep-i', stdout)
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)
        self.assertNotIn('missing', stdout)

        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'],
                                      test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertTrue(re.search('test-testdep-nodeps.*missing', stdout))
        self.assertTrue(re.search('test-testdep-i.*missing', stdout))
        self.assertTrue(re.search('test-testdep-g.*missing', stdout))
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)

        rmRf(test_dir)
Exemplo n.º 35
0
    def test_installNoTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install', '--test-dependencies', 'none'], test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir)
        self.assertIn('testmod', stdout)
        self.assertIn('other-testing-dummy', stdout)
        self.assertTrue(re.search('test-testing-dummy.*missing', stdout))
        self.assertTrue(re.search('test-target-dep.*missing', stdout))

        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir)
        self.assertIn('testmod', stdout)
        self.assertIn('other-testing-dummy', stdout)
        self.assertTrue(re.search('test-testing-dummy.*missing', stdout))
        self.assertTrue(re.search('test-target-dep.*missing', stdout))

        rmRf(test_dir)
Exemplo n.º 36
0
    def test_installAllComplexTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Complex_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install', '--test-dependencies', 'all'], test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-g', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertIn('test-testdep-i', stdout)
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)
        self.assertNotIn('missing', stdout)

        rmRf(test_dir)
Exemplo n.º 37
0
    def test_targetConfigMerge(self):
        test_dir = self.writeTestFiles(Test_Target_Config_Merge, True)

        os.chdir(test_dir)
        c = validate.currentDirectoryModule()
        target, errors = c.satisfyTarget('bar,')
        merged_config = target.getMergedConfig()

        self.assertIn("foo", merged_config)
        self.assertIn("bar", merged_config)
        self.assertIn("a", merged_config['foo'])
        self.assertIn("b", merged_config['foo'])
        self.assertIn("c", merged_config['foo'])
        self.assertEqual(merged_config['foo']['a'], 321)
        self.assertEqual(merged_config['foo']['b'], 456)
        self.assertEqual(merged_config['foo']['c'], 789)
        self.assertIn("bar", merged_config)
        self.assertIn("d", merged_config['bar'])
        self.assertEqual(merged_config['bar']['d'], "def")

        os.chdir(self.restore_cwd)
        rmRf(test_dir)
Exemplo n.º 38
0
    def test_installNoComplexTestDeps(self):
        test_dir = tempfile.mkdtemp()
        with open(os.path.join(test_dir, 'module.json'), 'w') as f:
            f.write(Test_Complex_Module_JSON)
        stdout = self.runCheckCommand(['--target', Test_Target, 'install', '--test-dependencies', 'none'], test_dir)

        # also sanity-check listing:
        stdout = self.runCheckCommand(['--target', Test_Target, 'ls'], test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        # e should be installed because it is both a test dep and non-test dep:
        # maybe it shouldn't show up in the listing without -a though?
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertNotIn('test-testdep-g', stdout)
        self.assertNotIn('test-testdep-i', stdout)
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)
        self.assertNotIn('missing', stdout)

        stdout = self.runCheckCommand(['--target', Test_Target, 'ls', '-a'], test_dir)

        self.assertIn('test-testdep-b', stdout)
        self.assertIn('test-testdep-c', stdout)
        self.assertIn('test-testdep-d', stdout)
        self.assertIn('test-testdep-e', stdout)
        self.assertIn('test-testdep-f', stdout)
        self.assertIn('test-testdep-h', stdout)
        self.assertTrue(re.search('test-testdep-nodeps.*missing', stdout))
        self.assertTrue(re.search('test-testdep-i.*missing', stdout))
        self.assertTrue(re.search('test-testdep-g.*missing', stdout))
        self.assertNotIn('test-testdep-j', stdout)
        self.assertNotIn('test-testdep-k', stdout)

        rmRf(test_dir)
Exemplo n.º 39
0
 def wrapped(*args, **kwargs):
     rmRf(os.path.join('tmp_yotta_settings', "config.json"))
     fn(*args, **kwargs)
Exemplo n.º 40
0
 def tearDownClass(cls):
     rmRf(cls.test_dir)
Exemplo n.º 41
0
 def tearDown(self):
     rmRf(self.test_dir)
Exemplo n.º 42
0
 def tearDownClass(cls):
     rmRf(cls.test_dir)
Exemplo n.º 43
0
Arquivo: vcs.py Projeto: bearsh/yotta
 def remove(self):
     # fsutils, , misc filesystem utils, internal
     from yotta.lib import fsutils
     fsutils.rmRf(self.worktree)
Exemplo n.º 44
0
 def tearDown(self):
     fsutils.rmRf(self.working_copy.directory)
Exemplo n.º 45
0
Arquivo: link.py Projeto: Timmmm/yotta
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    link_module_name = None
    if args.module_or_path:
        link_module_name = args.module_or_path
        err = validate.componentNameValidationError(args.module_or_path)
        if err:
            # check if the module name is really a path to a module
            if os.path.isdir(args.module_or_path):
                # make sure the first half of the link exists,
                src = os.path.abspath(args.module_or_path)
                # if it isn't a valid module, that's an error:
                dep = validate.directoryModule(src)
                if not dep:
                    logging.error("%s is not a valid module: %s", args.module_or_path, dep.getError())
                    return 1
                link_module_name = dep.getName()
                dst = os.path.join(folders.globalInstallDirectory(), link_module_name)
                errcode = tryLink(src, dst)
                if errcode:
                    return errcode
            else:
                logging.error("%s is neither a valid module name, nor a path to an existing module.", args.module_or_path)
                logging.error(err)
                return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_modules'))
        src = os.path.join(folders.globalInstallDirectory(), link_module_name)
        dst = os.path.join(os.getcwd(), 'yotta_modules', link_module_name)
        # if the component is already installed, rm it
        fsutils.rmRf(dst)
    else:
        fsutils.mkDirP(folders.globalInstallDirectory())

        src = os.getcwd()
        dst = os.path.join(folders.globalInstallDirectory(), c.getName())

    if link_module_name:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check if the thing we linked is actually a dependency, if it isn't
        # warn about that. To do this we may have to get the current target
        # description. This might fail, in which case we warn that we couldn't
        # complete the check:
        target = c.getTarget(args.target, args.config)
        if target:
            if not c.hasDependencyRecursively(link_module_name, target=target, test_dependencies=True):
                logging.warning(
                    '"%s" is not installed as a dependency, so will not '+
                    ' be built. Perhaps you meant to "yotta install %s" '+
                    'first?',
                    link_module_name,
                    link_module_name
                )
        else:
            logging.warning(
                'Could not check if linked module "%s" is installed as a '+
                'dependency, because target "%s" is not available. Run '
                '"yotta ls" to check.',
                link_module_name,
                args.target
            )
    else:
        logging.info('%s -> %s' % (dst, src))
    return tryLink(src, dst)
Exemplo n.º 46
0
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils
    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    c = None
    t = None
    link_target_name = None
    if args.target_or_path:
        link_target_name = args.target_or_path
        c = validate.currentDirectoryModule()
        if not c:
            return 1
        err = validate.targetNameValidationError(args.target_or_path)
        if err:
            # check if the target name is really a path to an existing target
            if os.path.isdir(args.target_or_path):
                # make sure the first half of the link exists,
                src = os.path.abspath(args.target_or_path)
                # if it isn't a valid target, that's an error:
                tgt = validate.directoryTarget(src)
                if not tgt:
                    logging.error("%s is not a valid target: %s", args.target_or_path, tgt.getError())
                    return 1
                link_target_name = tgt.getName()
                dst = os.path.join(folders.globalInstallDirectory(), link_target_name)
                errcode = tryLink(src, dst)
                if errcode:
                    return errcode
            else:
                logging.error(err)
                return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_targets'))
        src = os.path.join(folders.globalTargetInstallDirectory(), link_target_name)
        dst = os.path.join(os.getcwd(), 'yotta_targets', link_target_name)
        # if the target is already installed, rm it
        fsutils.rmRf(dst)
    else:
        t = validate.currentDirectoryTarget()
        if not t:
            return 1
        fsutils.mkDirP(folders.globalTargetInstallDirectory())
        src = os.getcwd()
        dst = os.path.join(folders.globalTargetInstallDirectory(), t.getName())

    broken_link = False
    if link_target_name:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            broken_link = True
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check that the linked target is actually set as the target (or is
        # inherited from by something set as the target), if it isn't, warn the
        # user:
        if c and link_target_name != nameFromTargetSpec(args.target):
            target = c.getTarget(args.target, args.config)
            if target:
                if not target.inheritsFrom(link_target_name):
                    logging.warning(
                        'target "%s" is not used by the current target (%s), so '
                        'this link will have no effect. Perhaps you meant to '
                        'use "yotta target <targetname>" to set the build '
                        'target first.',
                        link_target_name,
                        nameFromTargetSpec(args.target)
                    )
            else:
                logging.warning(
                    'Could not check if linked target "%s" is used by the '+
                    'current target "%s": run "yotta target" to check.',
                    link_target_name,
                    nameFromTargetSpec(args.target)
                )

    else:
        logging.info('%s -> %s' % (dst, src))
    try:
        fsutils.symlink(src, dst)
    except Exception as e:
        if broken_link:
            logging.error('failed to create link (create the first half of the link first)')
        else:
            logging.error('failed to create link: %s', e)
Exemplo n.º 47
0
 def tearDown(self):
     fsutils.rmRf(self.working_copy.directory)
Exemplo n.º 48
0
 def test_installRegistryRef(self):
     test_dir = tempfile.mkdtemp()
     stdout = self.runCheckCommand(
         ['--target', Test_Target, 'install', Test_Name], test_dir)
     rmRf(test_dir)
Exemplo n.º 49
0
 def wrapped(*args, **kwargs):
     rmRf(os.path.join('tmp_yotta_settings', "config.json"))
     fn(*args, **kwargs)
Exemplo n.º 50
0
 def tearDown(self):
     rmRf(self.test_dir)
Exemplo n.º 51
0
Arquivo: test.py Projeto: ntoll/yotta
 def test_testOutputFilterPassing(self):
     test_dir = self.writeTestFiles(Test_Fitler_Pass, True)
     stdout = self.runCheckCommand(
         ['--target', systemDefaultTarget(), 'test'], test_dir)
     rmRf(test_dir)