Skip to content

Commit 0ffd2fa

Browse files
authored
Merge pull request #10 from satamame/fix/issue-9
Fix/issue 9
2 parents e379d52 + 84b4b19 commit 0ffd2fa

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.eggs*
44
build/
55
dist/
6+
.venv/

fountain/fountain.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,33 @@
77
Further Edited by Manuel Senfft
88
"""
99

10+
import re
11+
import string
1012

1113
COMMON_TRANSITIONS = {'FADE OUT.', 'CUT TO BLACK.', 'FADE TO BLACK.'}
12-
UPPER_ALPHABETS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ÄÖÜ1234567890'
14+
UPPER_ALPHABETS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ1234567890'
15+
CHAR_NAME_LETTERS = UPPER_ALPHABETS + string.punctuation + ' '
16+
17+
paren_ptn = re.compile(r'\(.*?\)')
18+
19+
20+
def _is_character(line: str) -> bool:
21+
'''Test if line is valid as character name
22+
'''
23+
if line[0] == '@':
24+
return True
25+
26+
if line[0] in ['[', ']', ',', '(', ')']:
27+
return False
28+
29+
if line[0] not in UPPER_ALPHABETS:
30+
return False
31+
32+
# Remove parenthesis-enclosed parts in which any character is valid
33+
concise_line = paren_ptn.sub('', line)
34+
35+
# Remaining part should consist of uppercases and punctuation
36+
return all([(c in CHAR_NAME_LETTERS) for c in concise_line])
1337

1438

1539
class FountainElement:
@@ -305,9 +329,7 @@ def _parse_body(self, script_body):
305329
newlines_before > 0
306330
and index + 1 < len(script_body)
307331
and script_body[index + 1]
308-
and not line[0] in ['[', ']', ',', '(', ')']
309-
and (all([(c in UPPER_ALPHABETS) for c in full_strip])
310-
or full_strip[0] == '@')
332+
and _is_character(full_strip)
311333
):
312334
newlines_before = 0
313335
if full_strip[-1] == '^':

requirements_dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-e .
2+
pytest==8.3.3

tests/test_charname.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pytest
2+
from fountain import fountain
3+
4+
5+
def ftext2test(charname):
6+
'''Fountain text with a Character name for testing
7+
'''
8+
text = '\n'.join([
9+
'INT. CASINO - NIGHT',
10+
'',
11+
'THE DEALER eyes the new player warily.',
12+
'',
13+
charname,
14+
'Where is that pit boss?'
15+
])
16+
return text
17+
18+
19+
def test_normal():
20+
'''Normal parse process should not be broken
21+
'''
22+
text = ftext2test('JOHN')
23+
fobj = fountain.Fountain(text)
24+
25+
el = fobj.elements[0]
26+
assert el.element_type == 'Scene Heading'
27+
28+
el = fobj.elements[2]
29+
assert el.element_type == 'Action'
30+
31+
32+
charnames2test = [
33+
'JANE DOE',
34+
'@naomi',
35+
'BILL (O.S.)',
36+
'C-3PO',
37+
'GROUPIE #1',
38+
"SARAH'S FRIEND",
39+
'BILL / THE MONSTER',
40+
'MICHAEL (as DOROTHY)',
41+
]
42+
43+
44+
@pytest.mark.parametrize('charname', charnames2test)
45+
def test_charname(charname: str):
46+
'''Test various Character names (issue #9)
47+
'''
48+
text = ftext2test(charname)
49+
fobj = fountain.Fountain(text)
50+
51+
el = fobj.elements[4]
52+
assert el.element_type == 'Character'
53+
assert el.element_text == charname.removeprefix('@')

0 commit comments

Comments
 (0)