Beispiel #1
0
    def test_all_lines(self):
        data_file = HighlightedFile(DATA_FILE)

        # get the set of self-describing lines
        lines = data_file.lines()

        chars = data_file.chars_debug()
        self.assertEqual(323, len(chars))
        self.assertEqual(7, len(lines))

        usages = chars[0].usages
        self.assertTrue(usages is not None, "usages should be declared")
Beispiel #2
0
    def test_CreateChars(self):
        dataFile = HighlightedFile(DATA_FILE)

        # get the set of self-describing lines
        lines = dataFile.lines()
        self.assertEqual(7, len(lines))

        chars = dataFile.chars_debug()
        assert chars is not None

        self.assertEqual(323, len(chars))

        self.assertEqual("9", chars[0].letter)
        self.assertEqual("5", chars[1].letter)

        usages = chars[0].usages
        self.assertTrue(usages is not None, "usages should be declared")
        self.assertEqual(0, len(usages), "usages should start empty")
Beispiel #3
0
    def test_RecordTokens(self):
        dataFile = HighlightedFile(DATA_FILE)

        # get the set of self-describing lines
        lines = dataFile.lines()

        firstLine = lines[0]
        assert firstLine is not None

        tokens = firstLine.tokens()
        self.assertEqual(7, len(tokens))

        tool = "TOOL"
        field = "FIELD"
        value = "VALUE"
        units = "UNITS"

        tokens[0].record(tool, field, value, units)

        chars = dataFile.chars_debug()
        assert chars is not None

        first_entry = chars[0]
        self.assertEqual("9", first_entry.letter)
        self.assertEqual(1, len(first_entry.usages))

        first_usage = first_entry.usages[0]
        self.assertTrue(first_usage is not None, "should have a usage")
        self.assertEqual("TOOL/FIELD", first_usage.tool_field)
        self.assertEqual("Value:VALUE Units:UNITS", first_usage.message)

        # make another recordd
        firstLine.record(field, value)
        self.assertEqual(2, len(first_entry.usages))
        second_usage = first_entry.usages[1]
        self.assertTrue(second_usage is not None, "should have a usage")
        self.assertEqual("FIELD", second_usage.tool_field)
        self.assertEqual("VALUE", second_usage.message)
Beispiel #4
0
    def test_CombineSingleLine(self):
        dataFile = HighlightedFile(DATA_FILE, 1)

        # get the set of self-describing lines
        lines = dataFile.lines()

        tokens = lines[0].tokens()

        self.assertEqual(7, len(tokens))

        dateToken = tokens[0]
        timeToken = tokens[1]
        dateTimeToken = combine_tokens(dateToken, timeToken)

        date_time = self.parse_timestamp(dateToken.text(), timeToken.text())

        dateTimeToken.record("TOOL", "Date-Time", date_time, "N/A")

        chars = dataFile.chars_debug()
        assert chars is not None

        ctr = 0
        for char in chars:
            if ctr == 22:
                break
            ctr = ctr + 1

            if ctr > 0 and ctr <= 6:
                usages = char.usages
                self.assertEqual(1, len(usages))
                self.assertEqual("Value:1995-12-12 05:00:00 Units:N/A",
                                 usages[0].message)
            elif ctr > 7 and ctr <= 17:
                usages = char.usages
                self.assertEqual(1, len(usages))
                self.assertEqual("Value:1995-12-12 05:00:00 Units:N/A",
                                 usages[0].message)
Beispiel #5
0
        # event marker
        eventImporter = "Simple Event importer"
        dateToken = tokens[2]
        dateToken.record(eventImporter, "Date", dateToken.text())
        timeToken = tokens[3]
        timeToken.record(eventImporter, "Time", timeToken.text())
        eventToken = tokens[4]
        eventToken.record(eventImporter, "Event", timeToken.text())


        # and the whole=line record
        thisLine.record(eventImporter, "Whole line")

# output to file, display

for i in dataFile.chars_debug():
    print(i)

dataFile.export("out4.html")

# CSV FILE

dataFileCSV = HighlightedFile('data_highlight/file_comma.txt')

# get the set of self-describing lines
lines = dataFileCSV.lines()

CSV_DELIM = "(?:,\"|^\")(\"\"|[\w\W]*?)(?=\",|\"$)|(?:,(?!\")|^(?!\"))([^,]*?)(?=$|,)|(\r\n|\n)"

for thisLine in lines: