Skip to content

Commit

Permalink
Test around escaping \
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Dec 21, 2023
1 parent 1602452 commit a93ed4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion synapseutils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# This is looking for a comma that is not preceded by a backslash
COMMA_PATTERN = re.compile(r"(?<!\\),")
# This is looking for a single non-escaped backslash. \ is selected, \\ is not
BACKSLASH_PATTERN = re.compile(r"(?<!\\)\\")
BACKSLASH_PATTERN = re.compile(r"(?<!\\\\)(\\)(?!\\)")

tracer = trace.get_tracer("synapseclient")

Expand Down
24 changes: 22 additions & 2 deletions tests/integration/synapseutils/test_synapseutils_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def __init__(self):
self.f2 = utils.make_bogus_data_file(n=10)
self.f3 = "https://www.synapse.org"

self.header = "path parent used executed activityName synapseStore foo date_1 datetime_1 datetime_2 datetime_3 multiple_strings multiple_dates multiple_bools multiple_ints multiple_floats\n"
self.header = "path parent used executed activityName synapseStore foo date_1 datetime_1 datetime_2 datetime_3 multiple_strings multiple_dates multiple_bools multiple_ints multiple_floats annotation_with_escaped_commas annotation_with_escaped_backslash\n"
self.row1 = (
'%s %s %s "%s;https://www.example.com" provName bar 2020-01-01 2023-12-04T07:00:00Z 2023-12-05 23:37:02+00:00 2023-12-05 07:00:00+00:00 a,b,c,d 2020-01-01,2023-12-04T07:00:00.111Z,2023-12-05 23:37:02.333+00:00,2023-12-05 07:00:00+00:00 fAlSe,False,tRuE,True 1,2,3,4 1.2,3.4,5.6,7.8\n'
'%s %s %s "%s;https://www.example.com" provName bar 2020-01-01 2023-12-04T07:00:00Z 2023-12-05 23:37:02+00:00 2023-12-05 07:00:00+00:00 a,b,c,d 2020-01-01,2023-12-04T07:00:00.111Z,2023-12-05 23:37:02.333+00:00,2023-12-05 07:00:00+00:00 fAlSe,False,tRuE,True 1,2,3,4 1.2,3.4,5.6,7.8 my\, string with a comma,another\, string with a comma my\\\\ string with an escaped backslash,another\\\\ string with an escaped backslash\n'
% (
self.f1,
self.project.id,
Expand Down Expand Up @@ -212,6 +212,18 @@ def test_syncToSynapse(test_state):
np.nan,
]

assert new_anots.loc[:]["annotation_with_escaped_commas"].tolist() == [
"my\, string with a comma,another\, string with a comma",
np.nan,
np.nan,
]

assert new_anots.loc[:]["annotation_with_escaped_backslash"].tolist() == [
"my\\ string with an escaped backslash,another\\ string with an escaped backslash",
np.nan,
np.nan,
]

# Validate that the Annotations uploaded to Synapse are correct when retrieving
# them through syn.get. Also verify that they are parsed into the correct Python type
syn_id_first_file = new_df.loc[:]["id"][0]
Expand Down Expand Up @@ -239,6 +251,14 @@ def test_syncToSynapse(test_state):
assert synapse_file_instance.multiple_bools == [False, False, True, True]
assert synapse_file_instance.multiple_ints == [1, 2, 3, 4]
assert synapse_file_instance.multiple_floats == [1.2, 3.4, 5.6, 7.8]
assert synapse_file_instance.annotation_with_escaped_commas == [
"my, string with a comma",
"another, string with a comma",
]
assert synapse_file_instance.annotation_with_escaped_backslash == [
"my\ string with an escaped backslash",
"another\ string with an escaped backslash",
]

# Validate that provenance is correct
for provenanceType in ["executed", "used"]:
Expand Down

0 comments on commit a93ed4d

Please sign in to comment.