Skip to content
Freek Dijkstra edited this page Apr 29, 2012 · 12 revisions

Unit tests

downloadsample script

Download a Minecraft sample world from GitHub and verify the SHA256 checksum.

downloadsample.URL = 'https://github.com/downloads/twoolie/NBT/Sample_World.tar.gz'

URL to retrieve

downloadsample.workdir = '/Users/freek/Repository/NBT/tests'

Directory for download and extracting the sample files

downloadsample.worlddir = '/Users/freek/Repository/NBT/tests/Sample World'

Destination folder for the sample world.

downloadsample.checksums = {'Sample World/region/r.0.0.mca': 'd86e51c2adf35f82492e974f75fe83e9e5db56a267a3fe76150dc42f0aeb07c7', 'Sample World/region/r.0.1.mcr': '08fcd50748d4633a3b1d52e1b323c7dd9c4299a28ec095d0261fd195d3c9a537', 'Sample World/region/r.-1.1.mcr': '8e8b545b412a6a2bb519aee0259a63e6a918cd25a49538451e752e3bf90d4cf1', 'Sample World/level.dat_mcr': '933238e89a9f7f94c72f236da0d81d44d966c7a1544490e51e682ab42ccc50ff', 'Sample World/region/r.0.0.mcr': 'a8e7fea4e40a70e0d70dea7ebb1328c7623ed01b77d8aff34d01e530fbdad9d5', 'Sample World/region/r.-1.1.mca': 'c5f6fb5c72ca534d0f73662f2199dca977d2de1521b4823f73384aa6826c4b74', 'Sample World/region/r.0.1.mca': '8a03d910c7fd185ae5efb1409c592e4a9688dfab1fbd31f8c736461157a7675d', 'Sample World/data': None, 'Sample World/level.dat': 'f252cf8b938fa1e41c9335ea1bdc70fca73ac5c63c2cf2db4b2ddc4cb2fa4d91', 'Sample World/region/r.-1.0.mca': '6e8ec8698e2e68ca3ee2090da72e4f24c85f9db3f36191e5e33ebc8cafb209f2', 'Sample World/region': None, 'Sample World': None, 'Sample World/level.dat_old': 'c4b5a5c355d4f85c369604ca27ee349dba41adc4712a43a6f8c8399fe44071e7', 'Sample World/region/r.-1.0.mcr': '3a9ccafc6f64b98c0424814f44f1d0d3429cbb33448ff97e2e84ca649bfa16ae', 'Sample World/session.lock': 'd05da686dd04cd2ad1f660ddaa7645abc9fd9af396357a5b3256b437af0d7dba'}

SHA256 checksums for each file in the tar file. Directories MUST also be included (without trailing slash), with None as the checksum

downloadsample.download(url, destination)

Download the file from the specified URL, and extract the contents.

May raise an IOError (or one of it's subclasses) upon error, either in reading from the URL of writing to file.

downloadsample.extract(filename, workdir, filelist)

Extract contents of a tar file in workdir. The tar file may be compressed using gzip or bzip2.

For security, only files listed in filelist are extracted. Extraneous files will be logged as warning.

downloadsample.verify(checksums)

Verify if all given files are present and their SHA256 checksum is correct. Any files not explicitly listed are deleted.

checksums is a dict of file => checksum, with file a file relative to dir.

Returns a boolean indicating that all checksums are correct, and all files are present.

Any warnings and errors are printer to logger. Errors or exceptions result in a return value of False.

downloadsample.install(url='https://github.com/downloads/twoolie/NBT/Sample_World.tar.gz', workdir='/Users/freek/Repository/NBT/tests', checksums={'Sample World/region/r.0.0.mca': 'd86e51c2adf35f82492e974f75fe83e9e5db56a267a3fe76150dc42f0aeb07c7', 'Sample World/region/r.0.1.mcr': '08fcd50748d4633a3b1d52e1b323c7dd9c4299a28ec095d0261fd195d3c9a537', 'Sample World/region/r.-1.1.mcr': '8e8b545b412a6a2bb519aee0259a63e6a918cd25a49538451e752e3bf90d4cf1', 'Sample World/level.dat_mcr': '933238e89a9f7f94c72f236da0d81d44d966c7a1544490e51e682ab42ccc50ff', 'Sample World/region/r.0.0.mcr': 'a8e7fea4e40a70e0d70dea7ebb1328c7623ed01b77d8aff34d01e530fbdad9d5', 'Sample World/region/r.-1.1.mca': 'c5f6fb5c72ca534d0f73662f2199dca977d2de1521b4823f73384aa6826c4b74', 'Sample World/region/r.0.1.mca': '8a03d910c7fd185ae5efb1409c592e4a9688dfab1fbd31f8c736461157a7675d', 'Sample World/data': None, 'Sample World/level.dat': 'f252cf8b938fa1e41c9335ea1bdc70fca73ac5c63c2cf2db4b2ddc4cb2fa4d91', 'Sample World/region/r.-1.0.mca': '6e8ec8698e2e68ca3ee2090da72e4f24c85f9db3f36191e5e33ebc8cafb209f2', 'Sample World/region': None, 'Sample World': None, 'Sample World/level.dat_old': 'c4b5a5c355d4f85c369604ca27ee349dba41adc4712a43a6f8c8399fe44071e7', 'Sample World/region/r.-1.0.mcr': '3a9ccafc6f64b98c0424814f44f1d0d3429cbb33448ff97e2e84ca649bfa16ae', 'Sample World/session.lock': 'd05da686dd04cd2ad1f660ddaa7645abc9fd9af396357a5b3256b437af0d7dba'})

Download and extract a sample world, used for testing. The download file and sample world are stored in workdir.

Verifies the checksum of all files. Files without a checksum are not extracted.

downloadsample.temp_mcregion_world(worldfolder='/Users/freek/Repository/NBT/tests/Sample World')

Create a McRegion worldfolder in a temporary directory, based on the files in the given mixed worldfolder. Returns the temporary directory path.

downloadsample.temp_anvil_world(worldfolder='/Users/freek/Repository/NBT/tests/Sample World')

Create a Anvil worldfolder in a temporary directory, based on the files in the given mixed worldfolder. Returns the temporary directory path.

downloadsample.cleanup_temp_world(tmpfolder)

Remove a temporary directory

nbttests unit test

Unit tests for nbt.nbt Module

class class nbttests.BugfixTest(methodName='runTest')

Bases: unittest.case.TestCase

Bugfix regression tests.

testEmptyFiles()

Opening an empty file causes an uncaught exception. https://github.com/twoolie/NBT/issues/issue/4

testProperlyClosed()

test that files opened from a file name are closed after being written to. i.e. will read correctly in the future

class class nbttests.ReadWriteTest(methodName='runTest')

Bases: unittest.case.TestCase

test that we can read the test file correctly

setUp()

tearDown()

testReadBig()

testWriteBig()

testWriteback()

class class nbttests.TreeManipulationTest(methodName='runTest')

Bases: unittest.case.TestCase

setUp()

testRootNodeSetup()

testTagNumeric()

tearDown()

class class nbttests.EmptyStringTest(methodName='runTest')

Bases: unittest.case.TestCase

setUp()

testReadEmptyString()

testWriteEmptyString()

chunktests unit test

Unit tests for nbt.chunk Module

No tests available (yet)

regiontests unit test

Unit tests for nbt.region Module

No tests available (yet)

worldtests unit test

Unit tests for nbt.world Module

No tests available (yet)

Clone this wiki locally