Skip to content

Commit

Permalink
Fixes #1 missing last filename character, and adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobertos committed Apr 8, 2019
1 parent 7da3d07 commit 562293b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extractPackage("path/to/your/package.unitypackage", outputPath="optional/output/
#### Building
Install `pyinstaller` and run `build_exe.py`. I couldn't get this to work with Python 3.7 so I downloaded and ran it with 3.6 and it worked.

#### Testing
Install `pytest` and run `pytest -v -s` in the root directory.

#### Releasing
Refer to [the python docs on packaging for clarification](https://packaging.python.org/tutorials/packaging-projects/).
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
altgraph==0.16.1
atomicwrites==1.3.0
attrs==19.1.0
bleach==3.1.0
certifi==2019.3.9
chardet==3.0.4
colorama==0.4.1
docutils==0.14
future==0.17.1
idna==2.8
macholib==1.11
more-itertools==7.0.0
pefile==2018.8.8
pkginfo==1.5.0.1
pluggy==0.9.0
py==1.8.0
Pygments==2.3.1
pyinstall==0.1.4
PyInstaller==3.4
pytest==4.4.0
pywin32-ctypes==0.2.0
readme-renderer==24.0
requests==2.21.0
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.unitypackage - Should contain one file named test.txt with the contents "testing"
Empty file added tests/__init__.py
Empty file.
Binary file added tests/test.unitypackage
Binary file not shown.
28 changes: 28 additions & 0 deletions tests/test_testPackage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''
Tests for package extracting
'''
import os
import unittest
import tempfile

from unitypackage_extractor.extractor import extractPackage

class TestTestPackageExtract(unittest.TestCase):
'''
Tests the package extracting functionality
'''
def test_packageExtract(self):
'''should be able to extract a simple unity pckage'''
#arrange
with tempfile.TemporaryDirectory() as tmp:
#test.unitypackage - Should contain one file named test.txt with the contents "testing"

#act
print(f"Extracting to {tmp}...")
extractPackage("./tests/test.unitypackage", outputPath=tmp)

#assert
self.assertTrue(os.path.isdir(tmp))
self.assertTrue(os.path.isdir(f"{tmp}/Assets"))
self.assertTrue(os.path.isfile(f"{tmp}/Assets/test.txt"))
self.assertEqual(open(f"{tmp}/Assets/test.txt").read(), "testing")
3 changes: 2 additions & 1 deletion unitypackage_extractor/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def extractPackage(packagePath, outputPath=""):

#Extract the path name of the asset
pathname = upkg.extractfile(f"{name}/pathname").readline() #Reads the first line of the pathname file
pathname = pathname[:-1].decode("utf-8") #Remove the newling, and decode
pathname = pathname.decode("utf-8") #Decode
pathname = pathname[:-1] if pathname[-1] == '\n' else pathname #Remove newline
#Extract to the pathname
print(f"Extracting '{name}' as '{pathname}'")
assetFile = upkg.extractfile(f"{name}/asset")
Expand Down

0 comments on commit 562293b

Please sign in to comment.