This repository was archived by the owner on Aug 25, 2024. It is now read-only.
File tree 3 files changed +22
-1
lines changed 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
16
- New Model creation tutorial
17
17
- Added update functionality to the CSV source
18
18
- Added support for Gzip file source
19
+ - Added support for bz2 file source
19
20
### Changed
20
21
- Restructured documentation to docs folder and moved from rST to markdown
21
22
- Git feature cloc logs if no binaries are in path
Original file line number Diff line number Diff line change 3
3
import os
4
4
import abc
5
5
import asyncio
6
- import gzip
6
+ import gzip
7
+ import bz2
7
8
from .source import Source
8
9
from .log import LOGGER
9
10
@@ -42,6 +43,8 @@ async def _open(self):
42
43
return
43
44
if self .filename [::- 1 ].startswith (('.gz' )[::- 1 ]):
44
45
opener = gzip .open (self .filename , 'rt' )
46
+ elif self .filename [::- 1 ].startswith (('.bz2' )[::- 1 ]):
47
+ opener = bz2 .open (self .filename , 'rt' )
45
48
else :
46
49
opener = open (self .filename , 'r' )
47
50
with opener as fd :
@@ -54,6 +57,8 @@ async def _close(self):
54
57
if not self .readonly :
55
58
if self .filename [::- 1 ].startswith (('.gz' )[::- 1 ]):
56
59
close = gzip .open (self .filename , 'wt' )
60
+ elif self .filename [::- 1 ].startswith (('.bz2' )[::- 1 ]):
61
+ close = bz2 .open (self .filename , 'wt' )
57
62
else :
58
63
close = open (self .filename , 'w' )
59
64
with close as fd :
Original file line number Diff line number Diff line change @@ -71,6 +71,14 @@ async def test_open_gz(self):
71
71
await source .open ()
72
72
m_open .assert_called_once_with ('testfile.gz' , 'rt' )
73
73
74
+ async def test_open_bz2 (self ):
75
+ source = FakeFileSource ('testfile.bz2' )
76
+ m_open = mock_open ()
77
+ with patch ('os.path.exists' , return_value = True ), \
78
+ patch ('bz2.open' , m_open ):
79
+ await source .open ()
80
+ m_open .assert_called_once_with ('testfile.bz2' , 'rt' )
81
+
74
82
async def test_open_no_file (self ):
75
83
source = FakeFileSource ('testfile' )
76
84
with patch ('os.path.isfile' , return_value = False ):
@@ -91,6 +99,13 @@ async def test_close_gz(self):
91
99
await source .close ()
92
100
m_open .assert_called_once_with ('testfile.gz' , 'wt' )
93
101
102
+ async def test_close_bz2 (self ):
103
+ source = FakeFileSource ('testfile.bz2' )
104
+ m_open = mock_open ()
105
+ with patch ('bz2.open' , m_open ):
106
+ await source .close ()
107
+ m_open .assert_called_once_with ('testfile.bz2' , 'wt' )
108
+
94
109
async def test_close_readonly (self ):
95
110
source = FakeFileSource ('testfile:ro' )
96
111
m_open = mock_open ()
You can’t perform that action at this time.
0 commit comments