def test_process(self):
        line_count = 0
        for line in command.process('ls -l'):
            line_count += 1
        self.assertTrue(line_count >= 14)

        test_count = 0
        for line in command.process("ls -l | awk '{print $9}'",
                                    directory="Tests"):
            if line.startswith("test_"):
                test_count += 1
        self.assertTrue(test_count >= 2)

        for line in command.process("echo 'hi'"):
            self.assertTrue(line == "hi")

        for line in command.process("echo 'hi'", as_string=False):
            self.assertTrue(line == b'hi\n')

        with self.assertRaises(subprocess.CalledProcessError):
            for line in command.process("no-such-command"):
                self.fail("Should never see this: %s" % line)

        with self.assertRaises(FileNotFoundError):
            for line in command.process("ls -l",
                                        directory="/no/such/directory"):
                self.fail("Should never see this: %s" % line)

        with self.assertRaises(ValueError):
            for line in command.process(None):
                self.fail("Should never see this: %s" % line)

        with self.assertRaises(ValueError):
            for line in command.process(""):
                self.fail("Should never see this: %s" % line)
 def _get_project_directory(self, name: str) -> str:
     deriveddata = os.path.expanduser(self._xcode_derived_data_directory)
     if os.path.isdir(deriveddata):
         for line in command.process("find %s -type d -name %s" %
                                     (deriveddata, name)):
             if os.path.isdir(line):
                 return line
     logging.warning("Could not find '%s' inside '%s'", name, deriveddata)
     return None
Beispiel #3
0
def _find_file_match(pattern: str) -> str:
    files = []
    for line in command.process("find dist -name '%s'" % pattern):
        files.append(line)
    if len(files) == 0:
        raise RuntimeError("Could not find a dist file matching '%s'" %
                           pattern)
    if len(files) > 1:
        raise RuntimeError("Found more than one dist file matching '%s'" %
                           pattern)
    return files[0]
 def _get_pip_module_details(cls, pip: str) -> dict:
     details = {}
     for line in command.process("python3 -m pip show %s" % pip):
         detail = line.split(':', 1)
         assert len(
             detail) > 0, 'it should not be possible to get nothing here'
         key = detail[0]
         value = None
         if len(detail) > 1:
             value = detail[1].strip()
             if value == '':
                 value = None
             if key == 'Requires' and value is not None:
                 value = [x.strip() for x in value.split(',')]
         if value is not None:
             details[key] = value
     return details
Beispiel #5
0
def _has_match(cmd: str, match: str) -> bool:
    for line in command.process(cmd):
        if line.find(match) != -1:
            return True
    return False