Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
More pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed May 29, 2020
1 parent caec16c commit 582e038
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions tests/test_datapickler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import pickle

from pathlib import Path
from hashlib import sha256
from unittest import TestCase
from unittest.mock import Mock, patch
from unittest.mock import patch

from ospd.errors import OspdCommandError
from ospd.datapickler import DataPickler
Expand All @@ -34,22 +33,19 @@ def test_store_data(self):
data = {'foo', 'bar'}
filename = 'scan_info_1'
pickled_data = pickle.dumps(data)
m = sha256()
m.update(pickled_data)
tmp_hash = sha256()
tmp_hash.update(pickled_data)

data_pickler = DataPickler('/tmp')
ret = data_pickler.store_data(filename, data)

self.assertEqual(ret, m.hexdigest())
self.assertEqual(ret, tmp_hash.hexdigest())

data_pickler.remove_file(filename)

def test_store_data_failed(self):
data = {'foo', 'bar'}
filename = 'scan_info_1'
pickled_data = pickle.dumps(data)
m = sha256()
m.update(pickled_data)

data_pickler = DataPickler('/root')

Expand All @@ -58,14 +54,16 @@ def test_store_data_failed(self):
)

def test_store_data_check_permission(self):
OWNER_ONLY_RW_PERMISSION = '0o100600'
OWNER_ONLY_RW_PERMISSION = '0o100600' # pylint: disable=invalid-name
data = {'foo', 'bar'}
filename = 'scan_info_1'

data_pickler = DataPickler('/tmp')
data_pickler.store_data(filename, data)

file_path = Path(data_pickler._storage_path) / filename
file_path = (
Path(data_pickler._storage_path) / filename
) # pylint: disable=protected-access
self.assertEqual(
oct(file_path.stat().st_mode), OWNER_ONLY_RW_PERMISSION
)
Expand All @@ -80,9 +78,9 @@ def test_load_data(self):
filename = 'scan_info_1'
pickled_data = pickle.dumps(data)

m = sha256()
m.update(pickled_data)
pickled_data_hash = m.hexdigest()
tmp_hash = sha256()
tmp_hash.update(pickled_data)
pickled_data_hash = tmp_hash.hexdigest()

ret = data_pickler.store_data(filename, data)
self.assertEqual(ret, pickled_data_hash)
Expand All @@ -102,7 +100,6 @@ def test_remove_file_failed(self, mock_logger):

@patch("ospd.datapickler.logger")
def test_load_data_no_file(self, mock_logger):
data = {'foo', 'bar'}
filename = 'scan_info_1'
data_pickler = DataPickler('/tmp')

Expand All @@ -120,15 +117,17 @@ def test_load_data_corrupted(self):
filename = 'scan_info_1'
pickled_data = pickle.dumps(data)

m = sha256()
m.update(pickled_data)
pickled_data_hash = m.hexdigest()
tmp_hash = sha256()
tmp_hash.update(pickled_data)
pickled_data_hash = tmp_hash.hexdigest()

ret = data_pickler.store_data(filename, data)
self.assertEqual(ret, pickled_data_hash)

# courrupt data
file_to_corrupt = Path(data_pickler._storage_path) / filename
file_to_corrupt = (
Path(data_pickler._storage_path) / filename
) # pylint: disable=protected-access
with file_to_corrupt.open('ab') as f:
f.write(b'bar2')

Expand Down

0 comments on commit 582e038

Please sign in to comment.