# Path: operators/textparser/parser.py
# def text_to_srt(text, fps, reflow_long_lines=False):
#     """
#     Creates an SRT string out of plain text, with 1 second for each
#     segment
#     """
#     text = text.strip()
#     lines = text.split('\n')
# 
#     output = []
#     sec_time = 0
#     for i in range(len(lines)):
#         seg = str(i + 1) + '\n'
# 
#         start = seconds_to_srt_timecode(i + 0.00000001)
#         sec_time = i + 1.00000001
#         end = seconds_to_srt_timecode(sec_time)
#         seg += start + ' --> ' + end + '\n'
# 
#         if len(lines[i].rstrip()) > 31 and reflow_long_lines:
#             lines[i] = find_even_split(lines[i].rstrip())
# 
#         seg += lines[i] + '\n'
#         output.append(seg)
# 
#     return '\n'.join(output).rstrip()


import os
import sys
import unittest
from operators.textparser.parser import text_to_srt


file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, os.path.abspath(file_path))


class TestTextParser(unittest.TestCase):
    def setUp(self):
        self.static_path = os.path.join(file_path, 'tests', 'static')

        lyrics_path = os.path.join(self.static_path, 'I Move On.txt')
        f = open(lyrics_path)
        self.lyrics = f.read()
        f.close()

        lyrics_output_path = os.path.join(
            self.static_path, 'I Move On_unsynchronized.srt')
        f = open(lyrics_output_path)
        self.output = f.read().rstrip()
        f.close()

    def test_parsing(self):
        self.maxDiff = None

# Path: operators/textparser/parser.py
# def text_to_srt(text, fps, reflow_long_lines=False):
#     """
#     Creates an SRT string out of plain text, with 1 second for each
#     segment
#     """
#     text = text.strip()
#     lines = text.split('\n')
# 
#     output = []
#     sec_time = 0
#     for i in range(len(lines)):
#         seg = str(i + 1) + '\n'
# 
#         start = seconds_to_srt_timecode(i + 0.00000001)
#         sec_time = i + 1.00000001
#         end = seconds_to_srt_timecode(sec_time)
#         seg += start + ' --> ' + end + '\n'
# 
#         if len(lines[i].rstrip()) > 31 and reflow_long_lines:
#             lines[i] = find_even_split(lines[i].rstrip())
# 
#         seg += lines[i] + '\n'
#         output.append(seg)
# 
#     return '\n'.join(output).rstrip()


# Path: tests/test_textparser.py
import os
import sys
import unittest
from operators.textparser.parser import text_to_srt


file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, os.path.abspath(file_path))


class TestTextParser(unittest.TestCase):
    def setUp(self):
        self.static_path = os.path.join(file_path, 'tests', 'static')

        lyrics_path = os.path.join(self.static_path, 'I Move On.txt')
        f = open(lyrics_path)
        self.lyrics = f.read()
        f.close()

        lyrics_output_path = os.path.join(
            self.static_path, 'I Move On_unsynchronized.srt')
        f = open(lyrics_output_path)
        self.output = f.read().rstrip()
        f.close()

    def test_parsing(self):
        self.maxDiff = None

        self.assertEqual(text_to_srt(self.lyrics), self.output)
