Skip to content

Commit

Permalink
Going back to session scoped properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Oct 27, 2023
1 parent 450cc7c commit 468dd10
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 56 deletions.
28 changes: 0 additions & 28 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,6 @@ def project_teardown():
return proj


@pytest.fixture(scope="function")
def project_function(request, syn):
"""
Create a project to be shared at a function level scope.
"""

# Make one project
proj = syn.store(
Project(
name="integration_test_project_for_individual_functions_"
+ str(uuid.uuid4())
)
)

# set the working directory to a temp directory
_old_working_directory = os.getcwd()
working_directory = tempfile.mkdtemp(prefix="someTestFolder")
os.chdir(working_directory)

def project_teardown():
_cleanup(syn, [working_directory, proj])
os.chdir(_old_working_directory)

request.addfinalizer(project_teardown)

return proj


@pytest.fixture(scope="module")
def schedule_for_cleanup(request, syn):
"""Returns a closure that takes an item that should be scheduled for cleanup.
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/synapseclient/core/test_external_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def _syn(self, syn: Synapse):
self.syn = syn

@pytest.fixture(autouse=True)
def _project(self, project_function: Project):
self.project = project_function
def _project(self, project: Project):
self.project = project

@classmethod
def _make_temp_file(cls, contents=None, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@


@pytest.mark.flaky(reruns=3, only_rerun=["SynapseHTTPError"])
def test_round_trip(syn: Synapse, project_function: Project, schedule_for_cleanup):
def test_round_trip(syn: Synapse, project: Project, schedule_for_cleanup):
fhid = None
filepath = utils.make_bogus_binary_file(MIN_PART_SIZE + 777771)
try:
fhid = multipart_upload_file(syn, filepath)

# Download the file and compare it with the original
junk = File(parent=project_function, dataFileHandleId=fhid)
junk = File(parent=project, dataFileHandleId=fhid)
junk.properties.update(syn._createEntity(junk.properties))
(tmp_f, tmp_path) = tempfile.mkstemp()
schedule_for_cleanup(tmp_path)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/synapseclient/integration_test_Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ def test_store_activity(syn, project, schedule_for_cleanup):
assert honking["id"] == honking2["id"]


def test_store_isRestricted_flag(syn, project_function, schedule_for_cleanup):
def test_store_isRestricted_flag(syn, project, schedule_for_cleanup):
# Store a file with access requirements
path = utils.make_bogus_binary_file()
schedule_for_cleanup(path)
entity = File(path, name="Secret human data", parent=project_function)
entity = File(path, name="Secret human data", parent=project)

# We don't want to spam ACT with test emails
with patch(
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/synapseclient/test_command_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from io import StringIO


@pytest.fixture(scope="function")
def test_state(syn, project_function, schedule_for_cleanup):
@pytest.fixture(scope="module")
def test_state(syn: Synapse, project: Project, schedule_for_cleanup):
class State:
def __init__(self):
self.syn = syn
self.project = project_function
self.project = project
self.schedule_for_cleanup = schedule_for_cleanup
self.parser = cmdline.build_parser()
self.upload_filename = _create_temp_file_with_cleanup(schedule_for_cleanup)
Expand Down
12 changes: 5 additions & 7 deletions tests/integration/synapseclient/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def revert_timeout():


def test_create_and_update_file_view(
syn: Synapse, project_function: Project, schedule_for_cleanup
syn: Synapse, project: Project, schedule_for_cleanup
):
# Create a folder
folder = Folder(
str(uuid.uuid4()), parent=project_function, description="creating a file-view"
str(uuid.uuid4()), parent=project, description="creating a file-view"
)
folder = syn.store(folder)

Expand Down Expand Up @@ -90,7 +90,7 @@ def test_create_and_update_file_view(
addAnnotationColumns=False,
type="file",
columns=my_added_cols,
parent=project_function,
parent=project,
)

entity_view = syn.store(entity_view)
Expand Down Expand Up @@ -544,12 +544,10 @@ def test_synapse_integer_columns_with_missing_values_from_dataframe(
assert_frame_equal(df, df2)


def test_store_table_datetime(syn, project_function):
def test_store_table_datetime(syn, project):
current_datetime = datetime.fromtimestamp(round(time.time(), 3))
schema = syn.store(
Schema(
"testTable", [Column(name="testerino", columnType="DATE")], project_function
)
Schema("testTable", [Column(name="testerino", columnType="DATE")], project)
)
rowset = RowSet(rows=[Row([current_datetime])], schema=schema)
syn.store(Table(schema, rowset))
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/synapseclient/test_wikis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import synapseclient.core.utils as utils


def test_wikiAttachment(syn: Synapse, project_function: Project, schedule_for_cleanup):
def test_wikiAttachment(syn: Synapse, project: Project, schedule_for_cleanup):
# Upload a file to be attached to a Wiki
filename = utils.make_bogus_data_file()
attachname = utils.make_bogus_data_file()
Expand All @@ -26,7 +26,7 @@ def test_wikiAttachment(syn: Synapse, project_function: Project, schedule_for_cl
Blabber jabber blah blah boo.
"""
wiki = Wiki(
owner=project_function,
owner=project,
title="A Test Wiki",
markdown=md,
fileHandles=[fileHandle["id"]],
Expand All @@ -36,36 +36,36 @@ def test_wikiAttachment(syn: Synapse, project_function: Project, schedule_for_cl

# Create a Wiki sub-page
subwiki = Wiki(
owner=project_function,
owner=project,
title="A sub-wiki",
markdown="nothing",
parentWikiId=wiki.id,
)
subwiki = syn.store(subwiki)

# Retrieve the root Wiki from Synapse
wiki2 = syn.getWiki(project_function)
wiki2 = syn.getWiki(project)
# due to the new wiki api, we'll get back some new properties,
# namely markdownFileHandleId and markdown_path, so only compare
# properties that are in the first object
for property_name in wiki:
assert wiki[property_name] == wiki2[property_name]

# Retrieve the sub Wiki from Synapse
wiki2 = syn.getWiki(project_function, subpageId=subwiki.id)
wiki2 = syn.getWiki(project, subpageId=subwiki.id)
for property_name in wiki:
assert subwiki[property_name] == wiki2[property_name]

# Try making an update
wiki["title"] = "A New Title"
wiki["markdown"] = wiki["markdown"] + "\nNew stuff here!!!\n"
syn.store(wiki)
wiki = syn.getWiki(project_function)
wiki = syn.getWiki(project)
assert wiki["title"] == "A New Title"
assert wiki["markdown"].endswith("\nNew stuff here!!!\n")

# Check the Wiki's metadata
headers = syn.getWikiHeaders(project_function)
headers = syn.getWikiHeaders(project)
assert len(headers) == 2
assert headers[0]["title"] in (wiki["title"], subwiki["title"])

Expand All @@ -76,15 +76,15 @@ def test_wikiAttachment(syn: Synapse, project_function: Project, schedule_for_cl

syn.delete(subwiki)
syn.delete(wiki)
pytest.raises(SynapseHTTPError, syn.getWiki, project_function)
pytest.raises(SynapseHTTPError, syn.getWiki, project)


def test_create_or_update_wiki(syn, project_function):
def test_create_or_update_wiki(syn, project):
# create wiki once
syn.store(
Wiki(
title="This is the title",
owner=project_function,
owner=project,
markdown="#Wikis are OK\n\nBlabber jabber blah blah blither blather bonk!",
)
)
Expand All @@ -94,7 +94,7 @@ def test_create_or_update_wiki(syn, project_function):
wiki = syn.store(
Wiki(
title=new_title,
owner=project_function,
owner=project,
markdown="#Wikis are awesome\n\nNew babble boo flabble gibber wiggle sproing!",
),
createOrUpdate=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/synapseutils/test_synapseutils_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.integration import QUERY_TIMEOUT_SEC


@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(scope="module", autouse=True)
def test_state(syn: Synapse, schedule_for_cleanup):
class TestState:
def __init__(self):
Expand Down

0 comments on commit 468dd10

Please sign in to comment.