Skip to content

Commit

Permalink
Minor changes to avoid flake8 errors (#18)
Browse files Browse the repository at this point in the history
* Minor changes to avoid flake8 errors

* Renamed executors.py back to executers.py to avoid pytest error

* Fix new flake8 errors

* renamed 2nd testfunction test_no_id to test_id_len

* fix unittest test_no_id

---------

Co-authored-by: [email protected] <Haili Hu>
  • Loading branch information
hailihu authored Sep 3, 2024
1 parent feac0b5 commit 714da43
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.py[co]
.DS_Store

# Packages
*.egg
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"from picas.clients import CouchDB\n",
"from picas.iterators import TaskViewIterator, EndlessViewIterator\n",
"from picas.modifiers import BasicTokenModifier\n",
"from picas.executors import execute\n",
"from picas.executers import execute\n",
"from picas.util import Timer\n",
"\n",
"class ExampleActor(RunActor):\n",
Expand Down
1 change: 1 addition & 0 deletions picas/batchid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from os import environ


def add_batch_management_id(doc):
"""
Add job number id of the batch system to a token/document
Expand Down
6 changes: 4 additions & 2 deletions picas/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .documents import Document
from .picaslogger import picaslogger


class CouchDB:

"""Client class to handle communication with the CouchDB back-end."""
Expand Down Expand Up @@ -186,8 +187,9 @@ def delete_documents(self, docs):
try:
self.delete(doc)
except ResourceConflict as ex:
picaslogger.info(f"Could not delete document {doc.id} (rev {doc.rev}) "
"due to resource conflict: {str(ex)}", file=sys.stderr)
picaslogger.info(
f"Could not delete document {doc.id} (rev {doc.rev}) due to resource conflict: {str(ex)}",
file=sys.stderr)
result[i] = False
except Exception as ex:
picaslogger.info(f"Could not delete document {str(doc)}: {str(ex)}", file=sys.stderr)
Expand Down
1 change: 0 additions & 1 deletion picas/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class Task(Document):
'error': [],
}


def __init__(self, task=None):
if task is None:
task = {}
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[metadata]
description-file = README.md

[flake8]
max-line-length = 199
14 changes: 6 additions & 8 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class TestTask(unittest.TestCase):
def setUp(self):
self.task = Task({'_id': test_id})


def test_create(self):
doc = Document({'_id': test_id})
self.assertEqual(doc.id, test_id)
Expand All @@ -27,17 +26,17 @@ def test_create(self):
self.assertEqual(doc.id, test_other_id)
self.assertEqual(doc.value, {'_id': test_other_id})


def test_no_id(self):
doc = Document({'someattr': 1})
self.assertRaises(AttributeError, getattr(doc), 'id')
self.assertRaises(AttributeError, getattr(doc), 'rev')
with self.assertRaises(AttributeError):
getattr(doc, 'id')

with self.assertRaises(AttributeError):
getattr(doc, 'rev')

def test_empty(self):
Document({})


def test_attachment(self):
doc = Document()
data = b"This is it"
Expand All @@ -48,21 +47,20 @@ def test_attachment(self):
self.assertEqual(attach['content_type'], 'text/plain')
self.assertEqual(attach['data'], data)
self.assertEqual(doc['_attachments'][textfile]['data'],
base64.b64encode(data).decode())
base64.b64encode(data).decode())
doc.remove_attachment(textfile)
self.assertTrue(textfile not in doc['_attachments'])
self.assertEqual(attach['data'], data)
doc.put_attachment(jsonfile, b'{}')
attach = doc.get_attachment(jsonfile)
self.assertEqual(attach['content_type'], 'application/json')


def test_id(self):
self.assertEqual(self.task.id, test_id)
self.assertEqual(self.task.value['_id'], test_id)
self.assertEqual(self.task['_id'], test_id)

def test_no_id(self):
def test_id_len(self):
t = Task()
self.assertTrue(len(t.id) > 10)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_executors.py → tests/test_executers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from picas.executors import execute
from picas.executers import execute


class TestExecutors(unittest.TestCase):

Expand Down
1 change: 1 addition & 0 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from picas.generators import TokenGenerator


class TestGenerators(unittest.TestCase):

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_taskviewiterator(self):
self.assertEqual(len(self.db.saved), 1)

def stop_function(self, stop_value=2):
self.stop_value=stop_value
self.stop_value = stop_value
return len(self.db.saved) == stop_value

def test_endlessviewiterator(self):
Expand Down
1 change: 1 addition & 0 deletions tests/test_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from picas.documents import Task
from picas.modifiers import BasicTokenModifier


class TestModifier(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit 714da43

Please sign in to comment.