Skip to content

Commit

Permalink
Merge pull request #283 from sanger/bugfix_string_comparison
Browse files Browse the repository at this point in the history
Bugfix string comparison
  • Loading branch information
emrojo authored Mar 16, 2021
2 parents f2325fe + bd52e86 commit e44521b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions crawler/.release_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.8.1
2 changes: 1 addition & 1 deletion crawler/helpers/general_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_dart_well_index(coordinate: Optional[str]) -> Optional[int]:


def is_sample_positive(sample):
return sample.get(FIELD_RESULT, False) is POSITIVE_RESULT_VALUE
return sample.get(FIELD_RESULT, False) == POSITIVE_RESULT_VALUE


def is_sample_important_or_positive(sample):
Expand Down
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,19 @@ def blacklist_for_centre(config):
yield config
finally:
config.CENTRES[0]["file_names_to_ignore"] = []


def generate_new_object_for_string(original_str):
"""
For checking bug on comparing strings with 'is'
(Pdb) sample.get('Result', False) is 'Positive'
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
(Pdb) sample2.get('Result', False) is 'Positive'
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True
"""
part1 = original_str[0:2]
part2 = original_str[2:]
new_str = part1 + part2
return new_str
21 changes: 20 additions & 1 deletion tests/db/test_dart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
import pyodbc
import pytest

from crawler.constants import DART_STATE, DART_STATE_NO_PLATE, DART_STATE_NO_PROP, DART_STATE_PENDING
from crawler.constants import (
DART_STATE,
DART_STATE_NO_PLATE,
DART_STATE_NO_PROP,
DART_STATE_PENDING,
FIELD_RESULT,
POSITIVE_RESULT_VALUE,
)
from crawler.db.dart import (
add_dart_plate_if_doesnt_exist,
create_dart_sql_server_conn,
get_dart_plate_state,
set_dart_plate_state_pending,
set_dart_well_properties,
add_dart_well_properties_if_positive,
)
from crawler.exceptions import DartStateError
from crawler.sql_queries import (
Expand All @@ -19,6 +27,17 @@
SQL_DART_SET_WELL_PROPERTY,
)

from tests.conftest import generate_new_object_for_string


def test_add_dart_well_properties_if_positive(mlwh_connection):
with patch("crawler.db.dart.add_dart_well_properties") as mock_add_dart_well_properties:
cursor = mlwh_connection.cursor(dictionary=True)
sample = {FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE)}
plate_barcode = "aBarcode"
add_dart_well_properties_if_positive(cursor, sample, plate_barcode)
mock_add_dart_well_properties.assert_called_with(cursor, sample, plate_barcode)


def test_create_dart_sql_server_conn(config):
with patch("pyodbc.connect") as mock_connect:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
from crawler.db.mongo import get_mongo_collection
from crawler.file_processing import ERRORS_DIR, SUCCESSES_DIR, Centre, CentreFile
from crawler.types import Config, ModifiedRow
from tests.conftest import generate_new_object_for_string

# ----- tests helpers -----

Expand Down Expand Up @@ -1571,7 +1572,7 @@ def test_insert_plates_and_wells_from_docs_into_dart_multiple_new_plates(config)
FIELD_PLATE_BARCODE: "TC-rna-00000029",
FIELD_COORDINATE: "A01",
FIELD_LAB_ID: "AP",
FIELD_RESULT: POSITIVE_RESULT_VALUE,
FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE),
},
{
"_id": ObjectId("5f562d9931d9959b92544728"),
Expand All @@ -1580,7 +1581,7 @@ def test_insert_plates_and_wells_from_docs_into_dart_multiple_new_plates(config)
FIELD_PLATE_BARCODE: "TC-rna-00000024",
FIELD_COORDINATE: "B01",
FIELD_LAB_ID: "AP",
FIELD_RESULT: POSITIVE_RESULT_VALUE,
FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE),
},
{
"_id": ObjectId("5f562d9931d9959b92544728"),
Expand Down Expand Up @@ -1650,7 +1651,7 @@ def test_insert_plates_and_wells_from_docs_into_dart_single_new_plate_multiple_w
FIELD_PLATE_BARCODE: plate_barcode,
FIELD_COORDINATE: "A01",
FIELD_LAB_ID: "AP",
FIELD_RESULT: POSITIVE_RESULT_VALUE,
FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE),
},
{
"_id": ObjectId("5f562d9931d9959b92544728"),
Expand All @@ -1659,7 +1660,7 @@ def test_insert_plates_and_wells_from_docs_into_dart_single_new_plate_multiple_w
FIELD_PLATE_BARCODE: plate_barcode,
FIELD_COORDINATE: "A02",
FIELD_LAB_ID: "AP",
FIELD_RESULT: POSITIVE_RESULT_VALUE,
FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE),
},
{
"_id": ObjectId("5f562d9931d9959b92544728"),
Expand Down
6 changes: 4 additions & 2 deletions tests/test_general_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
)
from crawler.types import SampleDoc

from tests.conftest import generate_new_object_for_string


def test_get_config():
with pytest.raises(ModuleNotFoundError):
Expand Down Expand Up @@ -315,9 +317,9 @@ def test_create_source_plate_doc(freezer):


def test_is_sample_positive():
negative = "negative"
assert is_sample_positive({FIELD_RESULT: negative}) is False
assert is_sample_positive({FIELD_RESULT: "negative"}) is False
assert is_sample_positive({FIELD_RESULT: POSITIVE_RESULT_VALUE}) is True
assert is_sample_positive({FIELD_RESULT: generate_new_object_for_string(POSITIVE_RESULT_VALUE)}) is True


def test_is_sample_important_or_positive():
Expand Down

0 comments on commit e44521b

Please sign in to comment.