Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from janopae/test-and-fix-celtx-import
Browse files Browse the repository at this point in the history
Test and fix Celtx import
  • Loading branch information
limburgher authored Aug 31, 2022
2 parents afc04e9 + ba03397 commit 5000de8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/myimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,8 @@ def sanitizeStr(s):
def importCeltx(fileName, frame):
# Celtx files are zipfiles, and the script content is within a file
# called "script-xxx.html", where xxx can be random.

# the 5 MB limit is arbitrary, we just want to avoid getting a
# MemoryError exception for /dev/zero etc.
data = util.loadFile(fileName, frame, 5000000)

if data == None:
return None

if len(data) == 0:
wx.MessageBox("File is empty.", "Error", wx.OK, frame)

return None

buf = io.StringIO(data)

try:
z = zipfile.ZipFile(buf)
z = zipfile.ZipFile(fileName)
except:
wx.MessageBox("File is not a valid Celtx script file.", "Error", wx.OK, frame)
return None
Expand Down Expand Up @@ -290,7 +275,9 @@ def addElem(eleType, lns):
for para in root.xpath("/html/body/p"):
items = []
for line in para.itertext():
items.append(str(line.replace("\n", " ")))
text = line.replace("\n", " ").strip()
if text != '':
items.append(text)

lt = elemMap.get(para.get("class"), screenplay.ACTION)

Expand Down
3 changes: 3 additions & 0 deletions src/screenplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,9 @@ def __str__(self):
return config.lb2char(self.lb) + config.lt2char(self.lt)\
+ self.text

def __repr__(self)->str:
return self.__str__()

def __ne__(self, other):
return ((self.lt != other.lt) or (self.lb != other.lb) or
(self.text != other.text))
Expand Down
Binary file added tests/fixtures/test.celtx
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/test_myimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@

import myimport

def testImportCeltx()->None:
u.init()
location = os.path.dirname(__file__)
pathToTestScriptCeltx = os.path.join(location, "fixtures/test.celtx")

importedLines = myimport.importCeltx(pathToTestScriptCeltx,mock.Mock())

assert importedLines is not None

# in order to compare the screenplays, we need to reformat it with the same configuration as the loaded one
importedScreenplay = u.new()
importedScreenplay.lines = importedLines
importedScreenplay.reformatAll()

expectedScreenplay = u.load()

for line, expectedLine in zip(importedScreenplay.lines, expectedScreenplay.lines):
assert line == expectedLine

def testImportTextFile()->None:
u.init()
location = os.path.dirname(__file__)
Expand Down

0 comments on commit 5000de8

Please sign in to comment.