コード例 #1
0
    def test_scriptImportEmptyLineImport(self):
        result = self.__lineTransformer.transform(0, [
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            EmptyStringLine(),
            ImportLine('DataSentics.Greetings.Greeter2', 'Greeter2')
        ])

        self.assertLines([
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter'))
        ], result)
コード例 #2
0
    def test_scriptCellSeparatorBefore(self):
        result = self.__lineTransformer.transform(2, [
            CellSeparatorLine(),
            EmptyStringLine(),
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            StringLine('print("Hello world")')
        ])

        self.assertLines([
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter')),
            EmptyStringLine(),
            CellSeparatorLine()
        ], result)
コード例 #3
0
    def test_simple(self):
        result = self.__transformer.transform([
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            EmptyStringLine(),
            StringLine('print("Hello world")'),
            ImportLine('DataSentics.local_bootstrap', '*'),
            EmptyStringLine(),
            StringLine('a = 5'),
        ])

        expected = [
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            EmptyStringLine(),
            StringLine('print("Hello world")'),
            EmptyStringLine(),
            StringLine('a = 5'),
        ]

        self.assertLines(expected, result)
コード例 #4
0
    def parse(self, line):
        if line == '':
            return EmptyStringLine()

        matches = re.match('^#%%([ ]+[-]+)?', line)

        if matches is not None:
            return CellSeparatorLine(line)

        return StringLine(line)
コード例 #5
0
    def test_notebookCellSeparator(self):
        result = self.__lineTransformer.transform(0, [
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            CellSeparatorLine()
        ])

        self.assertLines([
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),)
        ], result)
コード例 #6
0
    def transform(self, index, parsedLines: list) -> list:
        length = len(parsedLines)

        output = []

        if index == 0:
            output += [CellSeparatorLine(), EmptyStringLine()]
        elif index > 0 and not self.__previousLineIsCellSeparator(
                parsedLines, index - 1):
            output += [CellSeparatorLine(), EmptyStringLine()]

        if index + 1 < length and self.__followingLineIsString(
                parsedLines, index + 1):
            output += [
                MagicRunLine(parsedLines[index]),
                EmptyStringLine(),
                CellSeparatorLine()
            ]
        else:
            output += [MagicRunLine(parsedLines[index])]

        return output
コード例 #7
0
    def test_multilineNotebook(self):
        result = self.__linesTransformer.transform([
            CellSeparatorLine(),
            EmptyStringLine(),
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            EmptyStringLine(),
            ImportLine('Foo.Bar', '*'),
            EmptyStringLine(),
            StringLine('print("Hello world")'),
            EmptyStringLine(),
            CellSeparatorLine(),
            ImportLine('Hello.World', '*'),
            EmptyStringLine(),
            CellSeparatorLine(),
            StringLine('a = 5'),
        ])

        expected = [
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter')),
            EmptyStringLine(),
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('Foo.Bar', '*')),
            EmptyStringLine(),
            CellSeparatorLine(),
            EmptyStringLine(), # TODO: chceme tedy empty string? Spíš ne
            StringLine('print("Hello world")'),
            EmptyStringLine(),
            CellSeparatorLine(),
            MagicRunLine(ImportLine('Hello.World', '*')),
            EmptyStringLine(),
            CellSeparatorLine(),
            StringLine('a = 5'),
        ]

        self.assertLines(expected, result)