Ejemplo n.º 1
0
    def get_dir(self) -> List[str]:
        """
        Get directories present in the current working directory


        Notes
        -----
        Internally, calls ``FTP.dir()`` and parses ``stdout`` response

        Returns
        -------
        List[str]
            List of directory names
        """
        dirs = []
        s = StringIO()
        with contextlib.redirect_stdout(s):
            self.session.dir()
        s = s.getvalue()
        for line in s.splitlines():
            try:
                folder_name = dir_parse.search(line).groups()[-1]
                dirs.append(folder_name)
            except AttributeError:
                continue
        return dirs
Ejemplo n.º 2
0
    def testCombined(self):
        input = "foo bar"

        grammar = textwrap.dedent(
            r"""grammar T4;
            options {
              language = Python3;
              }

            r returns [res]: (ID)+ EOF { $res = $text };

            ID: 'a'..'z'+;
            WS: ' '+ { $channel = HIDDEN };
            """)


        stdout = StringIO()

        lexerMod, parserMod = self.compileInlineGrammar(grammar, returnModule=True)
        parserMod.main(
            ['combined.py', '--rule', 'r'],
            stdin=StringIO(input),
            stdout=stdout
            )

        stdout = stdout.getvalue()
        self.assertEqual(len(stdout.splitlines()), 1, stdout)
Ejemplo n.º 3
0
def userDf2nxGraphDataFrame():
    csv = """user,comtype,contactedUser
             # u1
             u1,sms,u2
             u1,sms,u2
             u1,call,u2
             u1,sms,u3
             u1,call,u3
             u1,call,u4
             # u2
             u2,sms,u3
             u2,sms,u4
             u2,sms,u1
             # u3
             u3,call,u5
             u3,call,u4
             u3,call,u4
             u3,sms,u4
             u3,call,u5
             # u4
             u4,call,u1
             u4,call,u1
             u4,call,u1
             u4,sms,u5
             # u5
             u5,call,u4
             u5,sms,u4
             u5,sms,u4"""
    csv = StringIO('\n'.join(ln.strip() for ln in csv.splitlines()
                             if not ln.strip().startswith('#')))
    df = pd.DataFrame.from_csv(csv)
    return df
Ejemplo n.º 4
0
def stripCode(code):
    r"""strip comments from code

    Args:
        code (str/filelike obj): code to be processed

    Returns:
        str: stripped code
    """
    if isinstance(code, str):
        code = StringIO(code)
    code = _stripCom(code)
    result = []
    for line in iter(code.splitlines()):
        if line.isspace() or not line:  # Jump over empty lines
            continue
        result.append(line.rstrip())
    result.append("")
    return "\n".join(result)
Ejemplo n.º 5
0
def lint_test():
    from pylint.lint import Run as lint
    file = sys.argv[1]
    actual_output = StringIO()
    with redirect_stdout(actual_output):
        try:
            lint([file,
                "--msg-template='Line {line}, column {column}: {msg}'",
                '--disable=all',
                '--enable=' + ','.join(sorted(LINT_CHECKS.keys())), '--max-line-length=150']
            )
        except SystemExit:
            pass
    actual_output = actual_output.getvalue().strip()
    passed = (actual_output == '')
    if passed:
        print_result('Coding style okay.', passed, should_exit=True)
    else:
        transcript = dedent('''
        There are some coding style issues:

        {}
        ''').strip().format('\n'.join(actual_output.splitlines()[1:]))
        print_result(transcript, passed, should_exit=True)
Ejemplo n.º 6
0
    def testCombined(self):
        input = "foo bar"

        grammar = textwrap.dedent(r"""grammar T4;
            options {
              language = Python3;
              }

            r returns [res]: (ID)+ EOF { $res = $text };

            ID: 'a'..'z'+;
            WS: ' '+ { $channel = HIDDEN };
            """)

        stdout = StringIO()

        lexerMod, parserMod = self.compileInlineGrammar(grammar,
                                                        returnModule=True)
        parserMod.main(['combined.py', '--rule', 'r'],
                       stdin=StringIO(input),
                       stdout=stdout)

        stdout = stdout.getvalue()
        self.assertEqual(len(stdout.splitlines()), 1, stdout)