Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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
Пример #5
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)
    def toLineString(self, parsedLine: MagicRunLine) -> str:
        importLine = parsedLine.getImportLine()

        return '# MAGIC %run ' + self.__basePath + '/' + importLine.getFrom().replace('.', '/')