예제 #1
0
    def test_scriptCellSeparatorBeforeMissing(self):
        result = self.__lineTransformer.transform(2, [
            StringLine('print("Prvni")'),
            EmptyStringLine(),
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            StringLine('print("Hello world")')
        ])

        self.assertLines([
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter')),
            EmptyStringLine(),
            CellSeparatorLine()
        ], result)
예제 #2
0
    def test_scriptWithEmptyLine(self):
        result = self.__lineTransformer.transform(0, [
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            StringLine('print("Hello world")'),
            EmptyStringLine(),
            StringLine('a = 5')
        ])

        self.assertLines([
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter')),
            EmptyStringLine(),
            CellSeparatorLine()
        ], result)
    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_scriptDoubleImport(self):
        result = self.__lineTransformer.transform(0, [
            ImportLine('DataSentics.Greetings.Greeter', 'Greeter'),
            ImportLine('DataSentics.Greetings.Greeter2', 'Greeter2'),
            EmptyStringLine(),
            StringLine('a = 5')
        ])

        self.assertLines([
            CellSeparatorLine(),
            EmptyStringLine(),
            MagicRunLine(ImportLine('DataSentics.Greetings.Greeter', 'Greeter')),        
        ], result)
예제 #6
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)
예제 #7
0
 def toLineString(self, parsedLine: StringLine) -> str:
     return parsedLine.getString()