Skip to content

Commit d78720b

Browse files
committed
Initial commit
0 parents  commit d78720b

File tree

13 files changed

+437
-0
lines changed

13 files changed

+437
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
tests/__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
*.swp
7+
8+
# IDE files
9+
.idea/
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
.DS_Store
29+
.coverage
30+
31+
# Installer logs
32+
pip-log.txt
33+
pip-delete-this-directory.txt
34+

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2016, Kirill V. Lyadvinsky
2+
http://www.codeatcpp.com
3+
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
3. Neither the name of the copyright holder nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: init test clean
2+
3+
test:
4+
python3 -m unittest discover -v
5+
6+
init:
7+
pip-3.2 install -r requirements.txt
8+
9+
clean:
10+
rm -rf test/*.pyc
11+
rm -rf zxtools/*.pyc
12+
rm -rf test/__pycache__
13+
rm -rf zxtools/__pycache__
14+
15+
coverage:
16+
coverage run --source zxtools setup.py test
17+
coverage report -m
18+
19+
lint:
20+
pylint zxtools -f parseable -r n

README.md

Whitespace-only changes.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
numpy

setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python
2+
# vim: set fileencoding=utf-8 :
3+
4+
from setuptools import setup, find_packages
5+
6+
7+
with open('README.md') as f:
8+
readme = f.read()
9+
10+
with open('LICENSE') as f:
11+
license = f.read()
12+
13+
setup(
14+
name='zxtools',
15+
version='0.0.1',
16+
description='TR-DOS files utils',
17+
long_description=readme,
18+
author='Kirill V. Lyadvinsky',
19+
author_email='[email protected]',
20+
url='https://github.com/codeatcpp/zxtools',
21+
license=license,
22+
packages=find_packages(exclude=('test', 'docs')),
23+
test_suite="test"
24+
)
25+

test/__init__.py

Whitespace-only changes.

test/data/f_loader.asm

1.77 KB
Binary file not shown.

test/test_hobeta.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#! /usr/bin/env python
2+
# vim: set fileencoding=utf-8 :
3+
""" hobeta.py tests """
4+
5+
import os
6+
import io
7+
import struct
8+
import unittest
9+
import tempfile
10+
from collections import namedtuple
11+
from zxtools import hobeta
12+
13+
14+
class TestHobeta(unittest.TestCase):
15+
def test_ckechsum(self):
16+
data = b'F.load.AC\x00\x80\xf9\x06\x00\x07'
17+
self.assertEqual(hobeta.calc_checksum(data), 20661)
18+
19+
def test_format_size(self):
20+
header_len = struct.calcsize(hobeta.HEADER_FMT)
21+
self.assertEqual(header_len, 17)
22+
23+
def test_format(self):
24+
data = b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41" \
25+
b"\x43\x00\x80\xF9\x06\x00\x07\xB5\x50"
26+
record = hobeta.Header._make(struct.unpack_from(hobeta.HEADER_FMT, data))
27+
28+
self.assertEqual(record.filename, b"F.load.A")
29+
self.assertEqual(record.filetype, ord('C'))
30+
self.assertEqual(record.start, 32768)
31+
self.assertEqual(record.length, 1785)
32+
self.assertEqual(record.first_sector, 0)
33+
self.assertEqual(record.occupied_sectors, 7)
34+
self.assertEqual(record.check_sum, 20661)
35+
36+
def test_parse_info(self):
37+
test_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41\x43\x00\x80\xF9\x06\x00\x07\xB5"
38+
b"\x50\x00\x00\x3B\x20\x4C\x4F\x41\x44\x45\x52\x20\x66\x6F\x72\x20")
39+
header, crc = hobeta.parse_info(test_file)
40+
41+
self.assertEqual(header.filename, b"F.load.A")
42+
self.assertEqual(header.filetype, ord('C'))
43+
self.assertEqual(header.start, 32768)
44+
self.assertEqual(header.length, 1785)
45+
self.assertEqual(header.first_sector, 0)
46+
self.assertEqual(header.occupied_sectors, 7)
47+
self.assertEqual(header.check_sum, 20661)
48+
self.assertEqual(header.check_sum, crc)
49+
50+
def test_parse_info2(self):
51+
test_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41\x43\x00\x80\x02\x00\x00\x07\xB5"
52+
b"\x50\x00\x00\x3B\x20\x4C\x4F\x41\x44\x45\x52\x20\x66\x6F\x72\x20")
53+
header, crc = hobeta.parse_info(test_file)
54+
55+
self.assertEqual(header.filename, b"F.load.A")
56+
self.assertEqual(header.filetype, ord('C'))
57+
self.assertEqual(header.start, 32768)
58+
self.assertEqual(header.length, 2)
59+
self.assertEqual(header.first_sector, 0)
60+
self.assertEqual(header.occupied_sectors, 7)
61+
self.assertEqual(header.check_sum, 20661)
62+
self.assertNotEqual(header.check_sum, crc)
63+
64+
def strip_header(self, test_input_file, ignore_header_info):
65+
temp_output_path = tempfile.mkstemp()[1]
66+
temp_output_file = open(temp_output_path, "wb")
67+
Args = namedtuple('Args', "hobeta_file output_file ignore_header")
68+
parsed_args = Args(test_input_file, temp_output_file, ignore_header_info)
69+
copied_bytes = hobeta.strip_header(parsed_args)
70+
71+
return temp_output_path, copied_bytes
72+
73+
def test_strip_header1(self):
74+
test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41\x43\x00\x80\xF9\x06\x00\x07\xB5"
75+
b"\x50\x00\x00\x3B\x20\x4C\x4F\x41\x44\x45\x52\x20\x66\x6F\x72\x20")
76+
temp_output_path, bytes_count = self.strip_header(test_input_file, True)
77+
try:
78+
temp_output_file = open(temp_output_path, "rb")
79+
temp_output_file.seek(0, os.SEEK_END)
80+
self.assertEqual(temp_output_file.tell(), 15)
81+
self.assertEqual(bytes_count, 15)
82+
finally:
83+
temp_output_file.close()
84+
os.remove(temp_output_path)
85+
86+
def test_strip_header2(self):
87+
test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41\x43\x00\x80\xF9\x06\x00\x07\xB5"
88+
b"\x50\x00\x00\x3B\x20\x4C\x4F\x41\x44\x45\x52\x20\x66\x6F\x72\x20")
89+
temp_output_path, bytes_count = self.strip_header(test_input_file, False)
90+
try:
91+
temp_output_file = open(temp_output_path, "rb")
92+
temp_output_file.seek(0, os.SEEK_END)
93+
self.assertEqual(temp_output_file.tell(), 15)
94+
self.assertEqual(bytes_count, 15)
95+
finally:
96+
temp_output_file.close()
97+
os.remove(temp_output_path)
98+
99+
def test_strip_header3(self):
100+
test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41\x43\x00\x80\x0A\x00\x00\x07\xB5"
101+
b"\x50\x00\x00\x3B\x20\x4C\x4F\x41\x44\x45\x52\x20\x66\x6F\x72\x20")
102+
temp_output_path, bytes_count = self.strip_header(test_input_file, False)
103+
try:
104+
temp_output_file = open(temp_output_path, "rb")
105+
temp_output_file.seek(0, os.SEEK_END)
106+
self.assertEqual(temp_output_file.tell(), 10)
107+
self.assertEqual(bytes_count, 10)
108+
finally:
109+
temp_output_file.close()
110+
os.remove(temp_output_path)
111+
112+
113+
if __name__ == '__main__':
114+
unittest.main()

test/test_trdos.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python
2+
# vim: set fileencoding=utf-8 :
3+
""" trdos.py tests """
4+
5+
import unittest
6+
import struct
7+
from zxtools import trdos
8+
9+
10+
class TestTRDos(unittest.TestCase):
11+
def test_fat_format(self):
12+
data = b"filenameC\x00\x80\xf9\x06\x07\xC1\x01"
13+
record = trdos.FATRecord._make(struct.unpack_from(trdos.FAT_RECORD_FMT, data))
14+
15+
self.assertEqual(record.filename, b"filename")
16+
self.assertEqual(record.filetype, ord("C"))
17+
self.assertEqual(record.start, 32768)
18+
self.assertEqual(record.length, 1785)
19+
self.assertEqual(record.occupied_sectors, 0x07)
20+
self.assertEqual(record.first_sector, 0xC1)
21+
self.assertEqual(record.first_track, 0x01)
22+
23+
24+
if __name__ == '__main__':
25+
unittest.main()

zxtools/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)