Browse Source

Create .crlf.source file that are overwritten at testing time

pull/160/head
Oliverpool 9 years ago
parent
commit
6330c66483
  1. 43
      test/test_chordpro/newline.crlf.html
  2. 41
      test/test_chordpro/newline.crlf.sgc
  3. 2
      test/test_chordpro/newline.crlf.source
  4. 61
      test/test_chordpro/newline.crlf.tex
  5. 53
      test/test_chordpro/test_parser.py

43
test/test_chordpro/newline.crlf.html

@ -0,0 +1,43 @@
<span class="song-language">Lang: en</span><br>
<div class="song_content">
<p class="verse">This is a verse<br>
With a new line<br>
<br>
The second part of the verse<br>
Is this line
</p>
<p class="verse">Here is a new line at the end<br>
</p>
<p class="verse">Foo bar
</p>
<p class="verse"><br>
And a new line<br>
At the beginning
</p>
<p class="chorus">New lines can also<br>
<br>
Be in chorus
</p>
<p class="bridge">New lines can also<br>
<br>
Be in bridges
</p>
<p class="verse">New lines can also<br>
<br>
Be surrounded by spaces
</p>
<p class="verse">New lines cannot
</p>
</div>

41
test/test_chordpro/newline.crlf.sgc

@ -0,0 +1,41 @@
{lang: en}
This is a verse
With a new line
{newline}
The second part of the verse
Is this line
Here is a new line at the end
{newline}
Foo bar
{newline}
And a new line
At the beginning
{start_of_chorus}
New lines can also
{newline}
Be in chorus
{end_of_chorus}
{start_of_bridge}
New lines can also
{newline}
Be in bridges
{end_of_bridge}
New lines can also
{newline}
Be surrounded by spaces
New lines cannot

2
test/test_chordpro/newline.crlf.source

@ -0,0 +1,2 @@
# This content will be overwritten with `newline.source` content
# with windows line endings (CRLF) - for testing purposes

61
test/test_chordpro/newline.crlf.tex

@ -0,0 +1,61 @@
\selectlanguage{english}
\beginsong{}[
by={
},
]
\begin{verse}
This is a verse
With a new line
~\\
The second part of the verse
Is this line
\end{verse}
\begin{verse}
Here is a new line at the end
~\\
\end{verse}
\begin{verse}
Foo bar
\end{verse}
\begin{verse}
~\\
And a new line
At the beginning
\end{verse}
\begin{chorus}
New lines can also
~\\
Be in chorus
\end{chorus}
\begin{bridge}
New lines can also
~\\
Be in bridges
\end{bridge}
\begin{verse}
New lines can also
~\\
Be surrounded by spaces
\end{verse}
\begin{verse}
New lines cannot
\end{verse}
\endsong

53
test/test_chordpro/test_parser.py

@ -34,6 +34,14 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
maxDiff = None maxDiff = None
@classmethod
def setUpClass(cls):
cls._overwrite_clrf()
@classmethod
def tearDownClass(cls):
cls._reset_clrf()
@staticmethod @staticmethod
@contextlib.contextmanager @contextlib.contextmanager
def chdir(): def chdir():
@ -44,9 +52,11 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
yield yield
os.chdir(olddir) os.chdir(olddir)
def assertRender(self, destformat, sourcename, destname): # pylint: disable=invalid-name def assertRender(self, base, destformat): # pylint: disable=invalid-name
"""Assert that `sourcename` is correctly rendered as `destname` in `destformat`. """Assert that `{base}.source` is correctly rendered in the `destformat`.
""" """
sourcename = "{}.source".format(base)
destname = "{}.{}".format(base, destformat)
with self.chdir(): with self.chdir():
with open_read(destname) as expectfile: with open_read(destname) as expectfile:
with disable_logging(): with disable_logging():
@ -91,24 +101,35 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test that `base` is correctly parsed and rendered.""" """Test that `base` is correctly parsed and rendered."""
if base is None or dest is None: if base is None or dest is None:
return return
self.assertRender(dest, "{}.source".format(base), "{}.{}".format(base, dest)) self.assertRender(base, dest)
test_parse_render.__doc__ = ( test_parse_render.__doc__ = (
"Test that '{base}' is correctly parsed and rendererd into '{format}' format." "Test that '{base}' is correctly parsed and rendererd into '{format}' format."
).format(base=os.path.basename(base), format=dest) ).format(base=os.path.basename(base), format=dest)
return test_parse_render return test_parse_render
def test_clrf(self): @classmethod
"""Test that source is correctly parsed and rendered when line endings are CRLF. def _overwrite_clrf(cls):
"""Overwrite `*.crlf.source` files to force the CRLF line endings.
""" """
originalname = "newline.source" with cls.chdir():
chordproname = "newline.crlf.source" for crlfname in sorted(glob.glob('*.crlf.source')):
with self.chdir(): base = crlfname[:-len(".crlf.source")]
with open_read(originalname) as originalfile: sourcename = base + ".source"
with open(chordproname, 'w') as chordprofile: with open_read(sourcename) as sourcefile:
for line in originalfile: with open(crlfname, 'w') as crlffile:
chordprofile.write(line.replace('\n', '\r\n')) for line in sourcefile:
for dest in LANGUAGES: crlffile.write(line.replace('\n', '\r\n'))
with self.subTest(dest):
self.assertRender(dest, chordproname, "newline.{}".format(dest)) @classmethod
os.remove(chordproname) def _reset_clrf(cls):
"""Reset `*.crlf.source` files.
"""
crlf_msg = """# This content will be overwritten with `{}.source` content
# with windows line endings (CRLF) - for testing purposes
"""
with cls.chdir():
for crlfname in sorted(glob.glob('*.crlf.source')):
base = crlfname[:-len(".crlf.source")]
with open(crlfname, 'w') as crlffile:
crlffile.write(crlf_msg.format(base))

Loading…
Cancel
Save