-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from vidstige/better-tests
BSD support
- Loading branch information
Showing
10 changed files
with
141 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ __pycache__/ | |
|
||
/*.egg-info | ||
|
||
/test_data/ | ||
/test_data/file0.txt | ||
/test_data/file1.bin | ||
/test_data/test.a | ||
|
||
/dist/ | ||
/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from ar import Archive, ArchiveError | ||
|
||
|
||
BAD_ARCHIVE = Path('test_data/bad.a') | ||
|
||
|
||
def test_bad_file(): | ||
with BAD_ARCHIVE.open('rb') as f: | ||
with pytest.raises(ArchiveError) as exception_info: | ||
Archive(f) | ||
assert str(exception_info.value) == "Unexpected magic: b'nope, no'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# pylint: disable=redefined-outer-name | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from ar import Archive, ArchiveError | ||
|
||
|
||
ARCHIVE = Path('test_data/bsd.a') | ||
|
||
|
||
def test_list(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
actual = [entry.name for entry in archive] | ||
expected = ['file0.txt', 'file1.bin', 'long-filename.txt'] | ||
assert expected == actual | ||
|
||
|
||
def test_read_content(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file0.txt') | ||
assert file0.read(1) == 'H' | ||
assert file0.read() == 'ello' | ||
|
||
|
||
def test_read_content_long_filename(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('long-filename.txt') | ||
assert file0.read(1) == 'l' | ||
assert file0.read() == 'ong filename\n' | ||
|
||
def test_read_binary(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file1.bin', 'rb') | ||
assert file0.read() == b'\xc3\x28' | ||
|
||
|
||
def test_seek_basic(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file0.txt') | ||
file0.seek(1) | ||
assert file0.read(3) == 'ell' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# pylint: disable=redefined-outer-name | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from ar import Archive, ArchiveError | ||
|
||
|
||
ARCHIVE = Path('test_data/linux.a') | ||
|
||
|
||
def test_list(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
assert ['file0.txt', 'file1.bin'] == [entry.name for entry in archive] | ||
|
||
|
||
def test_read_content(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file0.txt') | ||
assert file0.read(1) == 'H' | ||
assert file0.read() == 'ello' | ||
|
||
|
||
def test_read_binary(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file1.bin', 'rb') | ||
assert file0.read() == b'\xc3\x28' | ||
|
||
|
||
def test_seek_basic(): | ||
with ARCHIVE.open('rb') as f: | ||
archive = Archive(f) | ||
file0 = archive.open('file0.txt') | ||
file0.seek(1) | ||
assert file0.read(3) == 'ell' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from ar import Archive, ArchiveError | ||
|
||
|
||
BAD_ARCHIVE = Path('test_data/bad.a') | ||
|
||
|
||
def test_bad_file(): | ||
with BAD_ARCHIVE.open('rt') as f: | ||
with pytest.raises(ArchiveError) as exception_info: | ||
Archive(f) | ||
assert str(exception_info.value) == "Stream must be binary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nope, not an ar file |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
!<arch> | ||
file0.txt/ 0 0 0 644 5 ` | ||
Hello | ||
file1.bin/ 0 0 0 644 2 ` | ||
�( |