Skip to content

Commit

Permalink
add a unit test for extracting a single text asset, mostly as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Jan 6, 2022
1 parent d74f70c commit 4ab30c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ If you need to modify it or amend it in some way, you should always appropriatel
Also see: [Github Help: Using Pull Requests](https://help.github.com/articles/using-pull-requests/)


### Running Tests

To run unit tests, simply run:

```bash
python3 -m unittest discover
```


### Need help?

You can always ask for help in our IRC channel, `#Hearthsim` on [Freenode](https://freenode.net/).
6 changes: 3 additions & 3 deletions unitypack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pkg_resources


__version__ = pkg_resources.require("unitypack")[0].version
if __name__ == '__main__':
import pkg_resources
__version__ = pkg_resources.require("unitypack")[0].version


def load(file, env=None):
Expand Down
Empty file added unitypack/test/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions unitypack/test/test_read_bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .. import *
import unittest
from .. import load
from pathlib import Path

def get_bundle_fixture(name):
return Path(__file__).parent / 'fixtures' / 'bundles' / name

class TestReadAssetBundle(unittest.TestCase):
def test_single_text_file(self):
with get_bundle_fixture("single-text-file-2019.3.13f1-no-compression").open("rb") as f:
bundle = load(f)
self.assertEqual(bundle.name, "CAB-2c069a3745be5cfe0c630ceac750b567")
self.assertFalse(bundle.compressed)
self.assertEqual(len(bundle.assets), 1)
asset = bundle.assets[0]
self.assertEqual(len(asset.objects), 2)
obj = list(asset.objects.items())[0][1]
self.assertEqual(obj.type, "TextAsset")
data = obj.read()
self.assertEqual(data.name, "example")
self.assertEqual(data.bytes, "ligma\n")

if __name__ == '__main__':
unittest.main()

0 comments on commit 4ab30c2

Please sign in to comment.