From 3134568bee9238b24df99a98bdcef00af00aa281 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Fri, 16 Jun 2023 19:51:03 +0000 Subject: [PATCH] Add decompyled source from binaries. --- tests/__init__.py | 65 ++- tests/schemas/adapted.py | 109 +++++ tests/schemas/advanced.py | 200 +++++++++ tests/schemas/default.py | 686 ++++++++++++++++++++++++++++ tests/schemas/external.py | 220 +++++++++ tests/schemas/privileges.py | 61 +++ tests/schemas/simple.py | 368 +++++++++++++++ tests/schemas/uuid.py | 68 +++ tests/test_adapted_attributes.py | 72 +++ tests/test_aggr_regressions.py | 194 ++++++++ tests/test_alter.py | 41 ++ tests/test_attach.py | 115 +++++ tests/test_autopopulate.py | 272 +++++++++++ tests/test_blob.py | 456 +++++++++++++++++++ tests/test_blob_matlab.py | 295 ++++++++++++ tests/test_bypass_serialization.py | 46 ++ tests/test_cascading_delete.py | 584 ++++++++++++++++++++++++ tests/test_declare.py | 636 ++++++++++++++++++++++++++ tests/test_dependencies.py | 79 ++++ tests/test_erd.py | 285 ++++++++++++ tests/test_external.py | 133 ++++++ tests/test_external_class.py | 123 +++++ tests/test_fetch.py | 694 +++++++++++++++++++++++++++++ tests/test_fetch_same.py | 118 +++++ tests/test_filepath.py | 383 ++++++++++++++++ tests/test_foreign_keys.py | 116 +++++ tests/test_groupby.py | 14 + tests/test_hash.py | 34 ++ tests/test_jobs.py | 262 +++++++++++ tests/test_json.py | 400 +++++++++++++++++ tests/test_log.py | 30 ++ tests/test_nan.py | 52 +++ tests/test_plugin.py | 94 ++++ tests/test_privileges.py | 156 +++++++ 34 files changed, 7440 insertions(+), 21 deletions(-) create mode 100644 tests/schemas/adapted.py create mode 100644 tests/schemas/advanced.py create mode 100644 tests/schemas/default.py create mode 100644 tests/schemas/external.py create mode 100644 tests/schemas/privileges.py create mode 100644 tests/schemas/simple.py create mode 100644 tests/schemas/uuid.py create mode 100644 tests/test_adapted_attributes.py create mode 100644 tests/test_aggr_regressions.py create mode 100644 tests/test_alter.py create mode 100644 tests/test_attach.py create mode 100644 tests/test_autopopulate.py create mode 100644 tests/test_blob.py create mode 100644 tests/test_blob_matlab.py create mode 100644 tests/test_bypass_serialization.py create mode 100644 tests/test_cascading_delete.py create mode 100644 tests/test_declare.py create mode 100644 tests/test_dependencies.py create mode 100644 tests/test_erd.py create mode 100644 tests/test_external.py create mode 100644 tests/test_external_class.py create mode 100644 tests/test_fetch.py create mode 100644 tests/test_fetch_same.py create mode 100644 tests/test_filepath.py create mode 100644 tests/test_foreign_keys.py create mode 100644 tests/test_groupby.py create mode 100644 tests/test_hash.py create mode 100644 tests/test_jobs.py create mode 100644 tests/test_json.py create mode 100644 tests/test_log.py create mode 100644 tests/test_nan.py create mode 100644 tests/test_plugin.py create mode 100644 tests/test_privileges.py diff --git a/tests/__init__.py b/tests/__init__.py index 8b825a042..c57f70146 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,14 +1,20 @@ import datajoint as dj from packaging import version -import pytest -import os +import pytest, os, urllib3, certifi, minio PREFIX = "djtest" CONN_INFO_ROOT = dict( - host=os.getenv("DJ_HOST"), - user=os.getenv("DJ_USER"), - password=os.getenv("DJ_PASS"), + host=(os.getenv("DJ_HOST")), + user=(os.getenv("DJ_USER")), + password=(os.getenv("DJ_PASS")), +) + +S3_CONN_INFO = dict( + endpoint=(os.getenv("DJ_HOST")), + access_key="datajoint", + secret_key="datajoint", + bucket="datajoint.test", ) @@ -17,9 +23,9 @@ def connection_root(): """Root user database connection.""" dj.config["safemode"] = False connection = dj.Connection( - host=os.getenv("DJ_HOST"), - user=os.getenv("DJ_USER"), - password=os.getenv("DJ_PASS"), + host=(os.getenv("DJ_HOST")), + user=(os.getenv("DJ_USER")), + password=(os.getenv("DJ_PASS")), ) yield connection dj.config["safemode"] = True @@ -29,12 +35,11 @@ def connection_root(): @pytest.fixture def connection_test(connection_root): """Test user database connection.""" - database = f"{PREFIX}%%" + target = f"`{PREFIX}%%`.*" credentials = dict( - host=os.getenv("DJ_HOST"), user="datajoint", password="datajoint" + host=(os.getenv("DJ_HOST")), user="datajoint", password="datajoint" ) permission = "ALL PRIVILEGES" - # Create MySQL users if version.parse( connection_root.query("select @@version;").fetchone()[0] @@ -42,14 +47,14 @@ def connection_test(connection_root): # create user if necessary on mysql8 connection_root.query( f""" - CREATE USER IF NOT EXISTS '{credentials["user"]}'@'%%' - IDENTIFIED BY '{credentials["password"]}'; + CREATE USER IF NOT EXISTS '{credentials['user']}'@'%%' + IDENTIFIED BY '{credentials['password']}'; """ ) connection_root.query( f""" - GRANT {permission} ON `{database}`.* - TO '{credentials["user"]}'@'%%'; + GRANT {permission} ON {target} + TO '{credentials['user']}'@'%%'; """ ) else: @@ -57,13 +62,31 @@ def connection_test(connection_root): # if not exists connection_root.query( f""" - GRANT {permission} ON `{database}`.* - TO '{credentials["user"]}'@'%%' - IDENTIFIED BY '{credentials["password"]}'; + GRANT {permission} ON {target} + TO '{credentials['user']}'@'%%' + IDENTIFIED BY '{credentials['password']}'; """ ) - - connection = dj.Connection(**credentials) + connection = (dj.Connection)(**credentials) yield connection - connection_root.query(f"""DROP USER `{credentials["user"]}`""") + connection_root.query(f"DROP USER `{credentials['user']}`") connection.close() + + +@pytest.fixture +def bucket(): + httpClient = urllib3.PoolManager( + timeout=30, + cert_reqs="CERT_REQUIRED", + ca_certs=(certifi.where()), + retries=urllib3.Retry( + total=3, backoff_factor=0.2, status_forcelist=[500, 502, 503, 504] + ), + ) + minioClient = minio.Minio( + **{k: v for k, v in S3_CONN_INFO.items() if k != "bucket"}, + **{"secure": True, "http_client": httpClient}, + ) + minioClient.make_bucket((S3_CONN_INFO["bucket"]), location="us-east-1") + yield + minioClient.remove_bucket(S3_CONN_INFO["bucket"]) diff --git a/tests/schemas/adapted.py b/tests/schemas/adapted.py new file mode 100644 index 000000000..50f73aeee --- /dev/null +++ b/tests/schemas/adapted.py @@ -0,0 +1,109 @@ +import pytest, datajoint as dj +from datajoint import errors +import tempfile, networkx as nx, json +from pathlib import Path +from .. import PREFIX, S3_CONN_INFO, bucket, connection_test + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_test_custom_datatype"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def graph(): + class GraphAdapter(dj.AttributeAdapter): + attribute_type = "longblob" + + @staticmethod + def get(obj): + return nx.Graph(obj) + + @staticmethod + def put(obj): + assert isinstance(obj, nx.Graph) + return list(obj.edges) + + graph = GraphAdapter() + yield graph + + +@pytest.fixture +def Connectivity(schema, graph): + errors._switch_adapted_types(True) + + @schema + class Connectivity(dj.Manual): + definition = """ + connid : int + --- + conn_graph = null : + """ + + yield Connectivity + Connectivity.drop() + errors._switch_adapted_types(False) + + +@pytest.fixture +def stores(): + dj.config["stores"] = dict() + yield dj.config["stores"] + del dj.config["stores"] + + +@pytest.fixture +def store(schema, bucket, stores): + with tempfile.TemporaryDirectory() as stage_dir: + store_name = "repo-s3" + dj.config["stores"][store_name] = dict( + S3_CONN_INFO, protocol="s3", location="adapted/repo", stage=stage_dir + ) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def Layout(schema, store, Connectivity): + errors._switch_adapted_types(True) + errors._switch_filepath_types(True) + + class LayoutToFilepath(dj.AttributeAdapter): + __doc__ = """ + An adapted data type that saves a graph layout into fixed filepath + """ + attribute_type = f"filepath@{store}" + + @staticmethod + def get(path): + with open(path, "r") as f: + return json.load(f) + + @staticmethod + def put(layout): + path = Path(dj.config["stores"][store]["stage"], "layout.json") + with open(str(path), "w") as f: + json.dump(layout, f) + return path + + layout_to_filepath = LayoutToFilepath() + + @schema + class Layout(dj.Manual): + definition = """ + # stores graph layout + -> Connectivity + --- + layout: + """ + + yield Layout + Layout.drop() + errors._switch_adapted_types(False) + errors._switch_filepath_types(False) diff --git a/tests/schemas/advanced.py b/tests/schemas/advanced.py new file mode 100644 index 000000000..13d6dd89f --- /dev/null +++ b/tests/schemas/advanced.py @@ -0,0 +1,200 @@ +import datajoint as dj, pytest +from .. import PREFIX, connection_test + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_advanced"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def Person(schema): + @schema + class Person(dj.Manual): + definition = """ + person_id : int + ---- + full_name : varchar(60) + sex : enum('M','F') + """ + + def fill(self): + """ + fill fake names from www.fakenamegenerator.com + """ + self.insert( + ( + (0, "May K. Hall", "F"), + (1, "Jeffrey E. Gillen", "M"), + (2, "Hanna R. Walters", "F"), + (3, "Russel S. James", "M"), + (4, "Robbin J. Fletcher", "F"), + (5, "Wade J. Sullivan", "M"), + (6, "Dorothy J. Chen", "F"), + (7, "Michael L. Kowalewski", "M"), + (8, "Kimberly J. Stringer", "F"), + (9, "Mark G. Hair", "M"), + (10, "Mary R. Thompson", "F"), + (11, "Graham C. Gilpin", "M"), + (12, "Nelda T. Ruggeri", "F"), + (13, "Bryan M. Cummings", "M"), + (14, "Sara C. Le", "F"), + (15, "Myron S. Jaramillo", "M"), + ) + ) + + yield Person + Person.drop() + + +@pytest.fixture +def Parent(schema, Person): + @schema + class Parent(dj.Manual): + definition = """ + -> Person + parent_sex : enum('M','F') + --- + -> Person.proj(parent='person_id') + """ + + def fill(self): + def make_parent(pid, parent): + return dict( + person_id=pid, + parent=parent, + parent_sex=((Person & {"person_id": parent}).fetch1("sex")), + ) + + self.insert( + ( + make_parent(*r) + for r in ( + (0, 2), + (0, 3), + (1, 4), + (1, 5), + (2, 4), + (2, 5), + (3, 4), + (3, 7), + (4, 7), + (4, 8), + (5, 9), + (5, 10), + (6, 9), + (6, 10), + (7, 11), + (7, 12), + (8, 11), + (8, 14), + (9, 11), + (9, 12), + (10, 13), + (10, 14), + (11, 14), + (11, 15), + (12, 14), + (12, 15), + ) + ) + ) + + yield Parent + Parent.drop() + + +@pytest.fixture +def Subject(schema, Person): + @schema + class Subject(dj.Manual): + definition = """ + subject : int + --- + -> [unique, nullable] Person + """ + + yield Subject + Subject.drop() + + +@pytest.fixture +def Prep(schema): + @schema + class Prep(dj.Manual): + definition = """ + prep : int + """ + + yield Prep + Prep.drop() + + +@pytest.fixture +def Slice(schema, Prep): + @schema + class Slice(dj.Manual): + definition = """ + -> Prep + slice : int + """ + + yield Slice + Slice.drop() + + +@pytest.fixture +def Cell(schema, Slice): + @schema + class Cell(dj.Manual): + definition = """ + -> Slice + cell : int + """ + + yield Cell + Cell.drop() + + +@pytest.fixture +def InputCell(schema, Cell): + @schema + class InputCell(dj.Manual): + definition = """ + # a synapse within the slice + -> Cell + -> Cell.proj(input="cell") + """ + + yield InputCell + InputCell.drop() + + +@pytest.fixture +def LocalSynapse(schema, Cell): + @schema + class LocalSynapse(dj.Manual): + definition = """ + # a synapse within the slice + -> Cell.proj(presynaptic='cell') + -> Cell.proj(postsynaptic='cell') + """ + + yield LocalSynapse + LocalSynapse.drop() + + +@pytest.fixture +def GlobalSynapse(schema, Cell): + @schema + class GlobalSynapse(dj.Manual): + definition = """ + # a synapse within the slice + -> Cell.proj(pre_slice="slice", pre_cell="cell") + -> Cell.proj(post_slice="slice", post_cell="cell") + """ + + yield GlobalSynapse + GlobalSynapse.drop() diff --git a/tests/schemas/default.py b/tests/schemas/default.py new file mode 100644 index 000000000..0e20fe524 --- /dev/null +++ b/tests/schemas/default.py @@ -0,0 +1,686 @@ +import datajoint as dj, numpy as np, random, inspect, pytest +from .. import PREFIX, connection_test + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_test1"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def TTest(schema): + @schema + class TTest(dj.Lookup): + __doc__ = """ + doc string + """ + definition = """ + key : int # key + --- + value : int # value + """ + contents = [(k, 2 * k) for k in range(10)] + + yield TTest + TTest.drop() + + +@pytest.fixture +def TTest2(schema): + @schema + class TTest2(dj.Manual): + definition = """ + key : int # key + --- + value : int # value + """ + + yield TTest2 + TTest2.drop() + + +@pytest.fixture +def TTest3(schema): + @schema + class TTest3(dj.Manual): + definition = """ + key : int + --- + value : varchar(300) + """ + + yield TTest3 + TTest3.drop() + + +@pytest.fixture +def NullableNumbers(schema): + @schema + class NullableNumbers(dj.Manual): + definition = """ + key : int + --- + fvalue = null : float + dvalue = null : double + ivalue = null : int + """ + + yield NullableNumbers + NullableNumbers.drop() + + +@pytest.fixture +def TTestExtra(schema): + @schema + class TTestExtra(dj.Manual): + __doc__ = """ + clone of TTest but with an extra field + """ + definition = """ + key : int # key + --- + value : int # value + extra : int # extra int + """ + + yield TTestExtra + TTestExtra.drop() + + +@pytest.fixture +def TTestNoExtra(schema): + @schema + class TTestNoExtra(dj.Manual): + __doc__ = """ + clone of TTest but with no extra fields + """ + definition = """ + key : int # key + --- + value : int # value + """ + + yield TTestNoExtra + TTestNoExtra.drop() + + +@pytest.fixture +def Auto(schema): + @schema + class Auto(dj.Lookup): + definition = """ + id :int auto_increment + --- + name :varchar(12) + """ + + def fill(self): + if not self: + self.insert( + [dict(name="Godel"), dict(name="Escher"), dict(name="Bach")] + ) + + yield Auto + Auto.drop() + + +@pytest.fixture +def User(schema): + @schema + class User(dj.Lookup): + definition = """ + # lab members + username: varchar(12) + """ + contents = [ + ["Jake"], + ["Cathryn"], + ["Shan"], + ["Fabian"], + ["Edgar"], + ["George"], + ["Dimitri"], + ] + + yield User + User.drop() + + +@pytest.fixture +def Subject(schema): + @schema + class Subject(dj.Lookup): + definition = """ + # Basic information about animal subjects used in experiments + subject_id :int # unique subject id + --- + real_id :varchar(40) # real-world name. Omit if the same as subject_id + species = "mouse" :enum('mouse', 'monkey', 'human') + date_of_birth :date + subject_notes :varchar(4000) + unique index (real_id, species) + """ + contents = [ + [1551, "1551", "mouse", "2015-04-01", "genetically engineered super mouse"], + [10, "Curious George", "monkey", "2008-06-30", ""], + [1552, "1552", "mouse", "2015-06-15", ""], + [1553, "1553", "mouse", "2016-07-01", ""], + ] + + yield Subject + Subject.drop() + + +@pytest.fixture +def Language(schema): + @schema + class Language(dj.Lookup): + definition = """ + # languages spoken by some of the developers + # additional comments are ignored + name : varchar(40) # name of the developer + language : varchar(40) # language + """ + contents = [ + ("Fabian", "English"), + ("Edgar", "English"), + ("Dimitri", "English"), + ("Dimitri", "Ukrainian"), + ("Fabian", "German"), + ("Edgar", "Japanese"), + ] + + yield Language + Language.drop() + + +@pytest.fixture +def Experiment(schema, Subject, User): + @schema + class Experiment(dj.Imported): + definition = """ + # information about experiments + -> Subject + experiment_id :smallint # experiment number for this subject + --- + experiment_date :date # date when experiment was started + -> [nullable] User + data_path="" :varchar(255) # file path to recorded data + notes="" :varchar(2048) # e.g. purpose of experiment + entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp + """ + fake_experiments_per_subject = 5 + + def make(self, key): + from datetime import date, timedelta + + users = [None, None] + list(User().fetch()["username"]) + self.insert( + ( + dict( + key, + experiment_id=experiment_id, + experiment_date=( + ( + date.today() + - timedelta(random.expovariate(0.03333333333333333)) + ).isoformat() + ), + username=(random.choice(users)), + ) + for experiment_id in range(self.fake_experiments_per_subject) + ) + ) + + yield Experiment + Experiment.drop() + + +@pytest.fixture +def Trial(schema, Experiment): + @schema + class Trial(dj.Imported): + definition = """ + # a trial within an experiment + -> Experiment.proj(animal='subject_id') + trial_id :smallint # trial number + --- + start_time :double # (s) + """ + + class Condition(dj.Part): + definition = """ + # trial conditions + -> Trial + cond_idx : smallint # condition number + ---- + orientation : float # degrees + """ + + def make(self, key): + """populate with random data (pretend reading from raw files)""" + trial = self.Condition() + for trial_id in range(10): + key["trial_id"] = trial_id + self.insert1(dict(key, start_time=(random.random() * 1000000000.0))) + trial.insert( + ( + dict( + key, cond_idx=cond_idx, orientation=(random.random() * 360) + ) + for cond_idx in range(30) + ) + ) + + yield Trial + Trial.drop() + + +@pytest.fixture +def Ephys(schema, Trial): + @schema + class Ephys(dj.Imported): + definition = """ + # some kind of electrophysiological recording + -> Trial + ---- + sampling_frequency :double # (Hz) + duration :decimal(7,3) # (s) + """ + + class Channel(dj.Part): + definition = """ + # subtable containing individual channels + -> master + channel :tinyint unsigned # channel number within Ephys + ---- + voltage : longblob + current = null : longblob # optional current to test null handling + """ + + def _make_tuples(self, key): + """ + populate with random data + """ + row = dict( + key, + sampling_frequency=6000, + duration=(np.minimum(2, random.expovariate(1))), + ) + self.insert1(row) + number_samples = int(row["duration"] * row["sampling_frequency"] + 0.5) + sub = self.Channel() + sub.insert( + ( + dict( + key, + channel=channel, + voltage=(np.float32(np.random.randn(number_samples))), + ) + for channel in range(2) + ) + ) + + yield Ephys + Ephys.drop() + + +@pytest.fixture +def Image(schema): + @schema + class Image(dj.Manual): + definition = """ + # table for testing blob inserts + id : int # image identifier + --- + img : longblob # image + """ + + yield Image + Image.drop() + + +@pytest.fixture +def UberTrash(schema): + @schema + class UberTrash(dj.Lookup): + definition = """ + id : int + --- + """ + contents = [(1,)] + + yield UberTrash + UberTrash.drop() + + +@pytest.fixture +def UnterTrash(schema, UberTrash): + @schema + class UnterTrash(dj.Lookup): + definition = """ + -> UberTrash + my_id : int + --- + """ + contents = [(1, 1), (1, 2)] + + yield UnterTrash + UnterTrash.drop() + + +@pytest.fixture +def SimpleSource(schema): + @schema + class SimpleSource(dj.Lookup): + definition = """ + id : int # id + """ + contents = ((x,) for x in range(10)) + + yield SimpleSource + SimpleSource.drop() + + +@pytest.fixture +def SigIntTable(schema, SimpleSource): + @schema + class SigIntTable(dj.Computed): + definition = """ + -> SimpleSource + """ + + def _make_tuples(self, key): + raise KeyboardInterrupt + + yield SigIntTable + SigIntTable.drop() + + +@pytest.fixture +def SigTermTable(schema, SimpleSource): + @schema + class SigTermTable(dj.Computed): + definition = """ + -> SimpleSource + """ + + def make(self, key): + raise SystemExit("SIGTERM received") + + yield SigTermTable + SigTermTable.drop() + + +@pytest.fixture +def DjExceptionName(schema): + @schema + class DjExceptionName(dj.Lookup): + definition = """ + dj_exception_name: char(64) + """ + + @property + def contents(self): + return [ + [member_name] + for member_name, member_type in inspect.getmembers(dj.errors) + if inspect.isclass(member_type) + if issubclass(member_type, Exception) + ] + + yield DjExceptionName + DjExceptionName.drop() + + +@pytest.fixture +def ErrorClass(schema, DjExceptionName): + @schema + class ErrorClass(dj.Computed): + definition = """ + -> DjExceptionName + """ + + def make(self, key): + exception_name = key["dj_exception_name"] + raise getattr(dj.errors, exception_name) + + yield ErrorClass + ErrorClass.drop() + + +@pytest.fixture +def DecimalPrimaryKey(schema): + @schema + class DecimalPrimaryKey(dj.Lookup): + definition = """ + id : decimal(4,3) + """ + contents = zip((0.1, 0.25, 3.99)) + + yield DecimalPrimaryKey + DecimalPrimaryKey.drop() + + +@pytest.fixture +def IndexRich(schema, Subject, User): + @schema + class IndexRich(dj.Manual): + definition = """ + -> Subject + --- + -> [unique, nullable] User.proj(first="username") + first_date : date + value : int + index (first_date, value) + """ + + yield IndexRich + IndexRich.drop() + + +@pytest.fixture +def ThingA(schema): + @schema + class ThingA(dj.Manual): + definition = """ + a: int + """ + + yield ThingA + ThingA.drop() + + +@pytest.fixture +def ThingB(schema): + @schema + class ThingB(dj.Manual): + definition = """ + b1: int + b2: int + --- + b3: int + """ + + yield ThingB + ThingB.drop() + + +@pytest.fixture +def ThingC(schema, ThingA, ThingB): + @schema + class ThingC(dj.Manual): + definition = """ + -> ThingA + --- + -> [unique, nullable] ThingB + """ + + yield ThingC + ThingC.drop() + + +@pytest.fixture +def Parent(schema): + @schema + class Parent(dj.Lookup): + definition = """ + parent_id: int + --- + name: varchar(30) + """ + contents = [(1, "Joe")] + + yield Parent + Parent.drop() + + +@pytest.fixture +def Child(schema, Parent): + @schema + class Child(dj.Lookup): + definition = """ + -> Parent + child_id: int + --- + name: varchar(30) + """ + contents = [(1, 12, "Dan")] + + yield Child + Child.drop() + + +@pytest.fixture +def ComplexParent(schema): + @schema + class ComplexParent(dj.Lookup): + definition = "\n".join(["parent_id_{}: int".format(i + 1) for i in range(8)]) + contents = [tuple((i for i in range(8)))] + + yield ComplexParent + ComplexParent.drop() + + +@pytest.fixture +def ComplexChild(schema, ComplexParent): + @schema + class ComplexChild(dj.Lookup): + definition = "\n".join( + ["-> ComplexParent"] + ["child_id_{}: int".format(i + 1) for i in range(1)] + ) + contents = [tuple((i for i in range(9)))] + + yield ComplexChild + ComplexChild.drop() + + +@pytest.fixture +def SubjectA(schema): + @schema + class SubjectA(dj.Lookup): + definition = """ + subject_id: varchar(32) + --- + dob : date + sex : enum('M', 'F', 'U') + """ + contents = [ + ("mouse1", "2020-09-01", "M"), + ("mouse2", "2020-03-19", "F"), + ("mouse3", "2020-08-23", "F"), + ] + + yield SubjectA + SubjectA.drop() + + +@pytest.fixture +def SessionA(schema, SubjectA): + @schema + class SessionA(dj.Lookup): + definition = """ + -> SubjectA + session_start_time: datetime + --- + session_dir='' : varchar(32) + """ + contents = [ + ("mouse1", "2020-12-01 12:32:34", ""), + ("mouse1", "2020-12-02 12:32:34", ""), + ("mouse1", "2020-12-03 12:32:34", ""), + ("mouse1", "2020-12-04 12:32:34", ""), + ] + + yield SessionA + SessionA.drop() + + +@pytest.fixture +def SessionStatusA(schema, SessionA): + @schema + class SessionStatusA(dj.Lookup): + definition = """ + -> SessionA + --- + status: enum('in_training', 'trained_1a', 'trained_1b', 'ready4ephys') + """ + contents = [ + ("mouse1", "2020-12-01 12:32:34", "in_training"), + ("mouse1", "2020-12-02 12:32:34", "trained_1a"), + ("mouse1", "2020-12-03 12:32:34", "trained_1b"), + ("mouse1", "2020-12-04 12:32:34", "ready4ephys"), + ] + + yield SessionStatusA + SessionStatusA.drop() + + +@pytest.fixture +def SessionDateA(schema, SubjectA): + @schema + class SessionDateA(dj.Lookup): + definition = """ + -> SubjectA + session_date: date + """ + contents = [ + ("mouse1", "2020-12-01"), + ("mouse1", "2020-12-02"), + ("mouse1", "2020-12-03"), + ("mouse1", "2020-12-04"), + ] + + yield SessionDateA + SessionDateA.drop() + + +@pytest.fixture +def Stimulus(schema): + @schema + class Stimulus(dj.Lookup): + definition = """ + id: int + --- + contrast: int + brightness: int + """ + + yield Stimulus + Stimulus.drop() + + +@pytest.fixture +def Longblob(schema): + @schema + class Longblob(dj.Manual): + definition = """ + id: int + --- + data: longblob + """ + + yield Longblob + Longblob.drop() diff --git a/tests/schemas/external.py b/tests/schemas/external.py new file mode 100644 index 000000000..d3cfa2805 --- /dev/null +++ b/tests/schemas/external.py @@ -0,0 +1,220 @@ +import datajoint as dj, tempfile, numpy as np, pytest +from .. import PREFIX, S3_CONN_INFO, connection_test, bucket + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_extern"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def stores(): + with tempfile.TemporaryDirectory() as cache_dir: + dj.config["cache"] = cache_dir + dj.config["stores"] = dict() + yield dj.config["stores"] + del dj.config["stores"] + + +@pytest.fixture +def store_raw(schema, stores): + with tempfile.TemporaryDirectory() as location_dir: + store_name = "raw" + dj.config["stores"][store_name] = dict(protocol="file", location=location_dir) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def store_repo(schema, stores): + with tempfile.TemporaryDirectory() as stage_dir: + with tempfile.TemporaryDirectory() as location_dir: + store_name = "repo" + dj.config["stores"][store_name] = dict( + stage=stage_dir, protocol="file", location=location_dir + ) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def store_repo_s3(schema, bucket, stores): + with tempfile.TemporaryDirectory() as stage_dir: + store_name = "repo-s3" + dj.config["stores"][store_name] = dict( + S3_CONN_INFO, protocol="s3", location="dj/repo", stage=stage_dir + ) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def store_local(schema, stores): + with tempfile.TemporaryDirectory() as location_dir: + store_name = "local" + dj.config["stores"][store_name] = dict( + protocol="file", location=location_dir, subfolding=(1, 1) + ) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def store_share(schema, bucket, stores): + store_name = "share" + dj.config["stores"][store_name] = dict( + S3_CONN_INFO, protocol="s3", location="dj/store/repo", subfolding=(2, 4) + ) + yield store_name + schema.external[store_name].delete(delete_external_files=True) + schema.connection.query( + f"DROP TABLE IF EXISTS `{schema.database}`.`~external_{store_name}`" + ) + del dj.config["stores"][store_name] + + +@pytest.fixture +def Simple(schema, store_local): + @schema + class Simple(dj.Manual): + definition = f""" + simple : int + --- + item : blob@{store_local} + """ + + yield Simple + Simple.drop() + + +@pytest.fixture +def SimpleRemote(schema, store_share): + @schema + class SimpleRemote(dj.Manual): + definition = f""" + simple : int + --- + item : blob@{store_share} + """ + + yield SimpleRemote + SimpleRemote.drop() + + +@pytest.fixture +def Seed(schema): + @schema + class Seed(dj.Lookup): + definition = """ + seed : int + """ + contents = zip(range(4)) + + yield Seed + Seed.drop() + + +@pytest.fixture +def Dimension(schema): + @schema + class Dimension(dj.Lookup): + definition = """ + dim : int + --- + dimensions : blob + """ + contents = ([0, [100, 50]], [1, [3, 4, 8, 6]]) + + yield Dimension + Dimension.drop() + + +@pytest.fixture +def Image(schema, Seed, Dimension, store_share, store_local): + @schema + class Image(dj.Computed): + definition = f""" + # table for storing + -> Seed + -> Dimension + ---- + img : blob@{store_share} # objects are stored as specified by dj.config['stores']['share'] + neg : blob@{store_local} # objects are stored as specified by dj.config['stores']['local'] + """ + + def make(self, key): + img = (np.random.rand)(*(Dimension() & key).fetch1("dimensions")) + self.insert1(dict(key, img=img, neg=(-img.astype(np.float32)))) + + yield Image + Image.drop() + + +@pytest.fixture +def Attach(schema, store_share): + @schema + class Attach(dj.Manual): + definition = f""" + # table for storing attachments + attach : int + ---- + img : attach@{store_share} # attachments are stored as specified by: dj.config['stores']['raw'] + txt : attach # attachments are stored directly in the database + """ + + yield Attach + Attach.drop() + + +@pytest.fixture +def Filepath(schema, store_repo): + dj.errors._switch_filepath_types(True) + + @schema + class Filepath(dj.Manual): + definition = f""" + # table for file management + fnum : int # test comment containing : + --- + img : filepath@{store_repo} # managed files + """ + + yield Filepath + Filepath.drop() + dj.errors._switch_filepath_types(False) + + +@pytest.fixture +def FilepathS3(schema, store_repo_s3): + dj.errors._switch_filepath_types(True) + + @schema + class FilepathS3(dj.Manual): + definition = f""" + # table for file management + fnum : int + --- + img : filepath@{store_repo_s3} # managed files + """ + + yield FilepathS3 + FilepathS3.drop() + dj.errors._switch_filepath_types(False) diff --git a/tests/schemas/privileges.py b/tests/schemas/privileges.py new file mode 100644 index 000000000..3ed725e7c --- /dev/null +++ b/tests/schemas/privileges.py @@ -0,0 +1,61 @@ +import datajoint as dj +import pytest + + +@pytest.fixture +def schema(): + schema = dj.Schema() + yield schema + schema.drop() + + +@pytest.fixture +def Parent(schema): + @schema + class Parent(dj.Lookup): + definition = """ + id: int + """ + contents = [(1,)] + + yield Parent + Parent.drop() + + +@pytest.fixture +def Child(schema, Parent): + @schema + class Child(dj.Computed): + definition = """ + -> Parent + """ + + def make(self, key): + self.insert1(key) + + yield Child + Child.drop() + + +@pytest.fixture +def NoAccess(schema): + @schema + class NoAccess(dj.Lookup): + definition = """ + string: varchar(10) + """ + + yield NoAccess + NoAccess.drop() + + +@pytest.fixture +def NoAccessAgain(schema, NoAccess): + @schema + class NoAccessAgain(dj.Manual): + definition = """ + -> NoAccess + """ + + yield NoAccessAgain + NoAccessAgain.drop() diff --git a/tests/schemas/simple.py b/tests/schemas/simple.py new file mode 100644 index 000000000..817bd25b1 --- /dev/null +++ b/tests/schemas/simple.py @@ -0,0 +1,368 @@ +"""A simple, abstract schema to test relational algebra""" + +import datajoint as dj, random, hashlib, uuid, numpy as np, itertools +from datetime import date, timedelta +import faker, pytest +from .. import PREFIX, connection_root, connection_test + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_relational"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def IJ(schema): + @schema + class IJ(dj.Lookup): + definition = """ + # tests restrictions + i : int + j : int + """ + contents = list((dict(i=i, j=(j + 2)) for i in range(3) for j in range(3))) + + yield IJ + IJ.drop() + + +@pytest.fixture +def JI(schema): + @schema + class JI(dj.Lookup): + definition = """ + # tests restrictions by relations when attributes are reordered + j : int + i : int + """ + contents = list((dict(i=(i + 1), j=j) for i in range(3) for j in range(3))) + + yield JI + JI.drop() + + +@pytest.fixture +def A(schema): + @schema + class A(dj.Lookup): + definition = """ + id_a :int + --- + cond_in_a :tinyint + """ + contents = [(i, i % 4 > i % 3) for i in range(10)] + + yield A + A.drop() + + +@pytest.fixture +def B(schema, A): + @schema + class B(dj.Computed): + definition = """ + -> A + id_b :int + --- + mu :float # mean value + sigma :float # standard deviation + n :smallint # number samples + """ + + class C(dj.Part): + definition = """ + -> B + id_c :int + --- + value :float # normally distributed variables according to parameters in B + """ + + def make(self, key): + sub = B.C() + for i in range(4): + key["id_b"] = i + mu = random.normalvariate(0, 10) + sigma = random.lognormvariate(0, 4) + n = random.randint(0, 10) + self.insert1(dict(key, mu=mu, sigma=sigma, n=n)) + sub.insert( + ( + dict(key, id_c=j, value=(random.normalvariate(mu, sigma))) + for j in range(n) + ) + ) + + yield B + B.drop() + + +@pytest.fixture +def L(schema): + @schema + class L(dj.Lookup): + definition = """ + id_l: int + --- + cond_in_l :tinyint + """ + contents = [(i, i % 3 >= i % 5) for i in range(30)] + + yield L + L.drop() + + +@pytest.fixture +def D(schema, A, L): + @schema + class D(dj.Computed): + definition = """ + -> A + id_d :int + --- + -> L + """ + + def _make_tuples(self, key): + lookup = list(L().fetch("KEY")) + self.insert((dict(key, id_d=i, **random.choice(lookup)) for i in range(4))) + + yield D + D.drop() + + +@pytest.fixture +def E(schema, B, D, L): + @schema + class E(dj.Computed): + definition = """ + -> B + -> D + --- + -> L + """ + + class F(dj.Part): + definition = """ + -> E + id_f :int + --- + -> B.C + """ + + def make(self, key): + self.insert1(dict(key, **random.choice(list(L().fetch("KEY"))))) + sub = E.F() + references = list((B.C() & key).fetch("KEY")) + random.shuffle(references) + sub.insert( + ( + dict(key, id_f=i, **ref) + for i, ref in enumerate(references) + if random.getrandbits(1) + ) + ) + + yield E + E.drop() + + +def F(schema): + @schema + class F(dj.Manual): + definition = """ + id: int + ---- + date=null: date + """ + + yield F + F.drop() + + +@pytest.fixture +def DataA(schema): + @schema + class DataA(dj.Lookup): + definition = """ + idx : int + --- + a : int + """ + contents = list(zip(range(5), range(5))) + + yield DataA + DataA.drop() + + +@pytest.fixture +def DataB(schema): + @schema + class DataB(dj.Lookup): + definition = """ + idx : int + --- + a : int + """ + contents = list(zip(range(5), range(5, 10))) + + yield DataB + DataB.drop() + + +@pytest.fixture +def Website(schema): + @schema + class Website(dj.Lookup): + definition = """ + url_hash : uuid + --- + url : varchar(1000) + """ + + def insert1_url(self, url): + hashed = hashlib.sha1() + hashed.update(url.encode()) + url_hash = uuid.UUID(bytes=(hashed.digest()[:16])) + self.insert1(dict(url=url, url_hash=url_hash), skip_duplicates=True) + return url_hash + + yield Website + Website.drop() + + +@pytest.fixture +def Profile(schema, Website): + @schema + class Profile(dj.Manual): + definition = """ + ssn : char(11) + --- + name : varchar(70) + residence : varchar(255) + blood_group : enum('A+', 'A-', 'AB+', 'AB-', 'B+', 'B-', 'O+', 'O-') + username : varchar(120) + birthdate : date + job : varchar(120) + sex : enum('M', 'F') + """ + + class Website(dj.Part): + definition = """ + -> master + -> Website + """ + + def populate_random(self, n=10): + fake = faker.Faker() + faker.Faker.seed(0) + for _ in range(n): + profile = fake.profile() + with self.connection.transaction: + self.insert1(profile, ignore_extra_fields=True) + for url in profile["website"]: + self.Website().insert1( + dict( + ssn=(profile["ssn"]), + url_hash=(Website().insert1_url(url)), + ) + ) + + yield Profile + Profile.drop() + + +@pytest.fixture +def TTestUpdate(schema): + np.random.seed(300) + + @schema + class TTestUpdate(dj.Lookup): + definition = """ + primary_key : int + --- + string_attr : varchar(255) + num_attr=null : float + blob_attr : longblob + """ + contents = [ + (0, "my_string", 0.0, np.random.randn(10, 2)), + (1, "my_other_string", 1.0, np.random.randn(20, 1)), + ] + + yield TTestUpdate + TTestUpdate.drop() + + +@pytest.fixture +def ArgmaxTest(schema): + np.random.seed(400) + + @schema + class ArgmaxTest(dj.Lookup): + definition = """ + primary_key : int + --- + secondary_key : char(2) + val : float + """ + n = 10 + + @property + def contents(self): + n = self.n + yield from zip( + range(n**2), + (itertools.chain)( + *itertools.repeat(tuple(map(chr, range(100, 100 + n))), n) + ), + np.random.rand(n**2), + ) + if False: + yield None + + yield ArgmaxTest + ArgmaxTest.drop() + + +@pytest.fixture +def ReservedWord(schema): + @schema + class ReservedWord(dj.Manual): + definition = """ + # Test of SQL reserved words + key : int + --- + in : varchar(25) + from : varchar(25) + int : int + select : varchar(25) + """ + + yield ReservedWord + ReservedWord.drop() + + +@pytest.fixture +def OutfitLaunch(schema): + @schema + class OutfitLaunch(dj.Lookup): + definition = """ + # Monthly released designer outfits + release_id: int + --- + day: date + """ + contents = [(0, date.today() - timedelta(days=15))] + + class OutfitPiece(dj.Part, dj.Lookup): + definition = """ + # Outfit piece associated with outfit + -> OutfitLaunch + piece: varchar(20) + """ + contents = [(0, "jeans"), (0, "sneakers"), (0, "polo")] + + yield OutfitLaunch + OutfitLaunch.drop() diff --git a/tests/schemas/uuid.py b/tests/schemas/uuid.py new file mode 100644 index 000000000..1f6f6a379 --- /dev/null +++ b/tests/schemas/uuid.py @@ -0,0 +1,68 @@ +import datajoint as dj, uuid, pytest +from .. import PREFIX, connection_test + +top_level_namespace_id = uuid.UUID("00000000-0000-0000-0000-000000000000") + + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + "_test1"), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def Basic(schema): + @schema + class Basic(dj.Manual): + definition = """ + item : uuid + --- + number : int + """ + + yield Basic + Basic.drop() + + +@pytest.fixture +def Topic(schema): + @schema + class Topic(dj.Manual): + definition = """ + # A topic for items + topic_id : uuid # internal identification of a topic, reflects topic name + --- + topic : varchar(8000) # full topic name used to generate the topic id + """ + + def add(self, topic): + """add a new topic with a its UUID""" + self.insert1( + dict(topic_id=(uuid.uuid5(top_level_namespace_id, topic)), topic=topic) + ) + + yield Topic + Topic.drop() + + +@pytest.fixture +def Item(schema, Topic): + @schema + class Item(dj.Computed): + definition = """ + item_id : uuid # internal identification of + --- + -> Topic + word : varchar(8000) + """ + key_source = Topic + + def make(self, key): + for word in ("Habenula", "Hippocampus", "Hypothalamus", "Hypophysis"): + self.insert1( + dict(key, word=word, item_id=(uuid.uuid5(key["topic_id"], word))) + ) + + yield Item + Item.drop() diff --git a/tests/test_adapted_attributes.py b/tests/test_adapted_attributes.py new file mode 100644 index 000000000..221dd4310 --- /dev/null +++ b/tests/test_adapted_attributes.py @@ -0,0 +1,72 @@ +import datajoint as dj, networkx as nx +from itertools import zip_longest +from .schemas import connection_root, connection_test, bucket +from schemas.adapted import schema, stores, store, graph, Connectivity, Layout + + +def test_adapted_type(Connectivity): + graphs = [ + nx.lollipop_graph(4, 2), + nx.star_graph(5), + nx.barbell_graph(3, 1), + nx.cycle_graph(5), + ] + Connectivity.insert(((i, g) for i, g in enumerate(graphs))) + returned_graphs = Connectivity().fetch("conn_graph", order_by="connid") + for g1, g2 in zip(graphs, returned_graphs): + assert isinstance(g2, nx.Graph) + assert len(g1.edges) == len(g2.edges) + assert 0 == len(nx.symmetric_difference(g1, g2).edges) + + +def test_adapted_filepath_type(Connectivity, Layout): + # https://github.com/datajoint/datajoint-python/issues/684 + + # Connectivity.delete() + Connectivity.insert1((0, nx.lollipop_graph(4, 2))) + layout = nx.spring_layout(Connectivity().fetch1("conn_graph")) + # make json friendly + layout = {str(k): [round(r, ndigits=4) for r in v] for k, v in layout.items()} + Layout.insert1((0, layout)) + result = Layout().fetch1("layout") + assert result == layout + + +def test_adapted_spawned(schema, Connectivity): + context = locals() + schema.spawn_missing_classes(context=context) + graphs = [ + nx.lollipop_graph(4, 2), + nx.star_graph(5), + nx.barbell_graph(3, 1), + nx.cycle_graph(5), + ] + context["Connectivity"].insert(((i, g) for i, g in enumerate(graphs))) + returned_graphs = context["Connectivity"]().fetch("conn_graph", order_by="connid") + for g1, g2 in zip(graphs, returned_graphs): + assert isinstance(g2, nx.Graph) + assert len(g1.edges) == len(g2.edges) + assert 0 == len(nx.symmetric_difference(g1, g2).edges) + + +def test_adapted_virtual(schema, Connectivity, graph): + virtual_module = dj.VirtualModule( + "virtual_module", (schema.database), add_objects={"graph": graph} + ) + c = virtual_module.Connectivity() + graphs = [ + nx.lollipop_graph(4, 2), + nx.star_graph(5), + nx.barbell_graph(3, 1), + nx.cycle_graph(5), + ] + c.insert(((i, g) for i, g in enumerate(graphs))) + c.insert1({"connid": 100}) + returned_graphs = c.fetch("conn_graph", order_by="connid") + for g1, g2 in zip_longest(graphs, returned_graphs): + if g1 is None: + assert g2 is None + else: + assert isinstance(g2, nx.Graph) + assert len(g1.edges) == len(g2.edges) + assert 0 == len(nx.symmetric_difference(g1, g2).edges) diff --git a/tests/test_aggr_regressions.py b/tests/test_aggr_regressions.py new file mode 100644 index 000000000..2d9802168 --- /dev/null +++ b/tests/test_aggr_regressions.py @@ -0,0 +1,194 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_aggr_regressions.py +# Compiled at: 2023-02-17 12:16:09 +# Size of source mod 2**32: 3916 bytes +__doc__ = '\nRegression tests for issues 386, 449, 484, and 558 — all related to processing complex aggregations and projections.\n' +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj, itertools, uuid, pytest +from . import PREFIX, connection_root, connection_test +from schemas.uuid import top_level_namespace_id, Topic, Item + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + '_aggr_regress'), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def R(schema): + + @schema + class R(dj.Lookup): + definition = '\n r : char(1)\n ' + contents = zip('ABCDFGHIJKLMNOPQRST') + + yield R + R.drop() + + +@pytest.fixture +def Q(schema, R): + + @schema + class Q(dj.Lookup): + definition = '\n -> R\n ' + contents = zip('ABCDFGH') + + yield Q + Q.drop() + + +@pytest.fixture +def S(schema, R): + + @schema + class S(dj.Lookup): + definition = '\n -> R\n s : int\n ' + contents = itertools.product('ABCDF', range(10)) + + yield S + S.drop() + + +def test_issue386(R, S, Q): + result = R.aggr(S, n='count(*)') & 'n=10' + result = Q & result + result.fetch() + + +def test_issue449(R, S): + result = dj.U('n') * R.aggr(S, n='max(s)') + result.fetch() + + +def test_issue484(S): + q = dj.U().aggr(S, n='max(s)') + n = q.fetch('n') + n = q.fetch1('n') + q = dj.U().aggr(S, n='avg(s)') + result = dj.U().aggr(q, m='max(n)') + result.fetch() + + +@pytest.fixture +def A(schema): + + @schema + class A(dj.Lookup): + definition = '\n id: int\n ' + contents = zip(range(10)) + + yield A + A.drop() + + +@pytest.fixture +def B(schema, A): + + @schema + class B(dj.Lookup): + definition = '\n -> A\n id2: int\n ' + contents = zip(range(5), range(5, 10)) + + yield B + B.drop() + + +@pytest.fixture +def X(schema): + + @schema + class X(dj.Lookup): + definition = '\n id: int\n ' + contents = zip(range(10)) + + yield X + X.drop() + + +def test_issue558_part1(A, B): + q = (A - B).proj(id2='3') + @py_assert3 = A - B + @py_assert4 = len(@py_assert3) + @py_assert9 = len(q) + @py_assert6 = @py_assert4 == @py_assert9 + if not @py_assert6: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s - %(py2)s))\n} == %(py10)s\n{%(py10)s = %(py7)s(%(py8)s)\n}', ), (@py_assert4, @py_assert9)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py2':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert9 = None + + +def test_issue558_part2(X): + d = dict(id=3, id2=5) + @py_assert3 = X & d + @py_assert4 = len(@py_assert3) + @py_assert10 = X & d + @py_assert11 = @py_assert10.proj + @py_assert13 = '3' + @py_assert15 = @py_assert11(id2=@py_assert13) + @py_assert17 = len(@py_assert15) + @py_assert6 = @py_assert4 == @py_assert17 + if not @py_assert6: + @py_format19 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py18)s\n{%(py18)s = %(py7)s(%(py16)s\n{%(py16)s = %(py12)s\n{%(py12)s = (%(py8)s & %(py9)s).proj\n}(id2=%(py14)s)\n})\n}', ), (@py_assert4, @py_assert17)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(X) if 'X' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(X) else 'X', 'py2':@pytest_ar._saferepr(d) if 'd' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(d) else 'd', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(X) if 'X' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(X) else 'X', 'py9':@pytest_ar._saferepr(d) if 'd' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(d) else 'd', 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_format21 = 'assert %(py20)s' % {'py20': @py_format19} + raise AssertionError(@pytest_ar._format_explanation(@py_format21)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert10 = @py_assert11 = @py_assert13 = @py_assert15 = @py_assert17 = None + + +def test_left_join_len(Topic, Item): + Topic().add('jeff') + Item.populate() + Topic().add('jeff2') + Topic().add('jeff3') + q = Topic.join((Item - dict(topic_id=(uuid.uuid5(top_level_namespace_id, 'jeff')))), + left=True) + qf = q.fetch() + @py_assert2 = len(q) + @py_assert7 = len(qf) + @py_assert4 = @py_assert2 == @py_assert7 + if not @py_assert4: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py8)s\n{%(py8)s = %(py5)s(%(py6)s)\n}', ), (@py_assert2, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py6':@pytest_ar._saferepr(qf) if 'qf' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(qf) else 'qf', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert7 = None + + +def test_union_join(A, B): + A.insert(zip([100,200,300,400,500,600])) + B.insert([(100, 11), (200, 22), (300, 33), (400, 44)]) + q1 = B & 'id < 300' + q2 = B & 'id > 300' + expected_data = [ + {'id':0, + 'id2':5}, + {'id':1, + 'id2':6}, + {'id':2, + 'id2':7}, + {'id':3, + 'id2':8}, + {'id':4, + 'id2':9}, + {'id':100, + 'id2':11}, + {'id':200, + 'id2':22}, + {'id':400, + 'id2':44}] + @py_assert2 = q1 + q2 + @py_assert4 = @py_assert2 * A + @py_assert5 = @py_assert4.fetch + @py_assert7 = True + @py_assert9 = @py_assert5(as_dict=@py_assert7) + @py_assert11 = @py_assert9 == expected_data + if not @py_assert11: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert11,), ('%(py10)s\n{%(py10)s = %(py6)s\n{%(py6)s = ((%(py0)s + %(py1)s) * %(py3)s).fetch\n}(as_dict=%(py8)s)\n} == %(py12)s', ), (@py_assert9, expected_data)) % {'py0':@pytest_ar._saferepr(q1) if 'q1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q1) else 'q1', 'py1':@pytest_ar._saferepr(q2) if 'q2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q2) else 'q2', 'py3':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(expected_data) if 'expected_data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(expected_data) else 'expected_data'} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = None \ No newline at end of file diff --git a/tests/test_alter.py b/tests/test_alter.py new file mode 100644 index 000000000..c21ec8cd9 --- /dev/null +++ b/tests/test_alter.py @@ -0,0 +1,41 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_alter.py +# Compiled at: 2023-02-17 13:52:50 +# Size of source mod 2**32: 1275 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from . import connection_root, connection_test +from schemas.default import schema, Subject, User, Experiment + +def test_alter(schema, Subject, User, Experiment): + Experiment.definition1 = ' # Experiment\n -> Subject\n experiment_id :smallint # experiment number for this subject\n ---\n data_path : int # some number\n extra=null : longblob # just testing\n -> [nullable] User\n subject_notes=null :varchar(2048) # {notes} e.g. purpose of experiment\n entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp\n ' + Experiment.original_definition = Experiment.definition + original = schema.connection.query('SHOW CREATE TABLE ' + Experiment.full_table_name).fetchone()[1] + Experiment.definition = Experiment.definition1 + Experiment.alter(prompt=False) + altered = schema.connection.query('SHOW CREATE TABLE ' + Experiment.full_table_name).fetchone()[1] + @py_assert1 = original != altered + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('!=', ), (@py_assert1,), ('%(py0)s != %(py2)s', ), (original, altered)) % {'py0':@pytest_ar._saferepr(original) if 'original' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original) else 'original', 'py2':@pytest_ar._saferepr(altered) if 'altered' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(altered) else 'altered'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + Experiment.definition = Experiment.original_definition + Experiment().alter(prompt=False) + restored = schema.connection.query('SHOW CREATE TABLE ' + Experiment.full_table_name).fetchone()[1] + @py_assert1 = altered != restored + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('!=', ), (@py_assert1,), ('%(py0)s != %(py2)s', ), (altered, restored)) % {'py0':@pytest_ar._saferepr(altered) if 'altered' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(altered) else 'altered', 'py2':@pytest_ar._saferepr(restored) if 'restored' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restored) else 'restored'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + @py_assert1 = original == restored + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (original, restored)) % {'py0':@pytest_ar._saferepr(original) if 'original' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original) else 'original', 'py2':@pytest_ar._saferepr(restored) if 'restored' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restored) else 'restored'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None \ No newline at end of file diff --git a/tests/test_attach.py b/tests/test_attach.py new file mode 100644 index 000000000..5df9e1a8b --- /dev/null +++ b/tests/test_attach.py @@ -0,0 +1,115 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_attach.py +# Compiled at: 2023-02-17 16:53:19 +# Size of source mod 2**32: 2660 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import tempfile, random, sys +from pathlib import Path +from . import connection_root, connection_test, bucket +from schemas.external import schema, stores, store_share, Attach + +def test_attach_attributes(Attach): + """test saving files in attachments""" + with tempfile.TemporaryDirectory() as source_folder: + with tempfile.TemporaryDirectory() as download_folder: + random.seed('attach') + table = Attach() + for i in range(2): + attach1 = Path(source_folder, 'attach1.img') + data1 = random.getrandbits(800).to_bytes(100, sys.byteorder) + with attach1.open('wb') as f: + f.write(data1) + attach2 = Path(source_folder, 'attach2.txt') + data2 = random.getrandbits(1600).to_bytes(200, sys.byteorder) + with attach2.open('wb') as f: + f.write(data2) + table.insert1(dict(attach=i, img=attach1, txt=attach2)) + + keys, path1, path2 = table.fetch('KEY', + 'img', 'txt', download_path=download_folder, order_by='KEY') + @py_assert0 = path1[0] + @py_assert3 = path2[0] + @py_assert2 = @py_assert0 != @py_assert3 + if not @py_assert2: + @py_format5 = @pytest_ar._call_reprcompare(('!=', ), (@py_assert2,), ('%(py1)s != %(py4)s', ), (@py_assert0, @py_assert3)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert0 = @py_assert2 = @py_assert3 = None + @py_assert0 = path1[0] + @py_assert3 = path1[1] + @py_assert2 = @py_assert0 != @py_assert3 + if not @py_assert2: + @py_format5 = @pytest_ar._call_reprcompare(('!=', ), (@py_assert2,), ('%(py1)s != %(py4)s', ), (@py_assert0, @py_assert3)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert0 = @py_assert2 = @py_assert3 = None + @py_assert1 = path1[0] + @py_assert3 = Path(@py_assert1) + @py_assert5 = @py_assert3.parent + @py_assert10 = Path(download_folder) + @py_assert7 = @py_assert5 == @py_assert10 + if not @py_assert7: + @py_format12 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n}.parent\n} == %(py11)s\n{%(py11)s = %(py8)s(%(py9)s)\n}', ), (@py_assert5, @py_assert10)) % {'py0':@pytest_ar._saferepr(Path) if 'Path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Path) else 'Path', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(Path) if 'Path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Path) else 'Path', 'py9':@pytest_ar._saferepr(download_folder) if 'download_folder' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(download_folder) else 'download_folder', 'py11':@pytest_ar._saferepr(@py_assert10)} + @py_format14 = 'assert %(py13)s' % {'py13': @py_format12} + raise AssertionError(@pytest_ar._format_explanation(@py_format14)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert10 = None + with Path(path1[-1]).open('rb') as f: + check1 = f.read() + with Path(path2[-1]).open('rb') as f: + check2 = f.read() + @py_assert1 = data1 == check1 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data1, check1)) % {'py0':@pytest_ar._saferepr(data1) if 'data1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data1) else 'data1', 'py2':@pytest_ar._saferepr(check1) if 'check1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(check1) else 'check1'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + @py_assert1 = data2 == check2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data2, check2)) % {'py0':@pytest_ar._saferepr(data2) if 'data2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data2) else 'data2', 'py2':@pytest_ar._saferepr(check2) if 'check2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(check2) else 'check2'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + p1, p2 = (Attach & keys[0]).fetch1('img', 'txt', download_path=download_folder) + @py_assert2 = path1[0] + @py_assert1 = p1 == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (p1, @py_assert2)) % {'py0':@pytest_ar._saferepr(p1) if 'p1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(p1) else 'p1', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + @py_assert2 = path2[0] + @py_assert1 = p2 == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (p2, @py_assert2)) % {'py0':@pytest_ar._saferepr(p2) if 'p2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(p2) else 'p2', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + + +def test_return_string(Attach): + """test returning string on fetch""" + with tempfile.TemporaryDirectory() as source_folder: + with tempfile.TemporaryDirectory() as download_folder: + random.seed('attach') + table = Attach() + attach1 = Path(source_folder, 'attach1.img') + data1 = random.getrandbits(800).to_bytes(100, sys.byteorder) + with attach1.open('wb') as f: + f.write(data1) + attach2 = Path(source_folder, 'attach2.txt') + data2 = random.getrandbits(1600).to_bytes(200, sys.byteorder) + with attach2.open('wb') as f: + f.write(data2) + table.insert1(dict(attach=2, img=attach1, txt=attach2)) + keys, path1, path2 = table.fetch('KEY', + 'img', 'txt', download_path=download_folder, order_by='KEY') + @py_assert1 = path1[0] + @py_assert4 = isinstance(@py_assert1, str) + if not @py_assert4: + @py_format6 = 'assert %(py5)s\n{%(py5)s = %(py0)s(%(py2)s, %(py3)s)\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py5':@pytest_ar._saferepr(@py_assert4)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert4 = None \ No newline at end of file diff --git a/tests/test_autopopulate.py b/tests/test_autopopulate.py new file mode 100644 index 000000000..cd131314a --- /dev/null +++ b/tests/test_autopopulate.py @@ -0,0 +1,272 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_autopopulate.py +# Compiled at: 2023-02-17 19:13:57 +# Size of source mod 2**32: 4120 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from datajoint import DataJointError +import random, pytest +from . import PREFIX, connection_root, connection_test +from schemas.default import schema, Subject, User, Experiment, Trial, Ephys + +def test_populate(Subject, Experiment, Trial, Ephys): + random.seed('populate') + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + @py_assert1 = Experiment() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('table already filled?') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + Experiment.populate() + @py_assert2 = Experiment() + @py_assert4 = len(@py_assert2) + @py_assert9 = Subject() + @py_assert11 = len(@py_assert9) + @py_assert14 = Experiment.fake_experiments_per_subject + @py_assert16 = @py_assert11 * @py_assert14 + @py_assert6 = @py_assert4 == @py_assert16 + if not @py_assert6: + @py_format17 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == (%(py12)s\n{%(py12)s = %(py7)s(%(py10)s\n{%(py10)s = %(py8)s()\n})\n} * %(py15)s\n{%(py15)s = %(py13)s.fake_experiments_per_subject\n})', ), (@py_assert4, @py_assert16)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py13':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format19 = 'assert %(py18)s' % {'py18': @py_format17} + raise AssertionError(@pytest_ar._format_explanation(@py_format19)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert9 = @py_assert11 = @py_assert14 = @py_assert16 = None + @py_assert1 = Trial() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('table already filled?') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + restriction = Subject.proj(animal='subject_id').fetch('KEY')[0] + d = Trial.connection.dependencies + d.load() + Trial.populate(restriction) + @py_assert1 = Trial() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('table was not populated') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + key_source = Trial.key_source + @py_assert3 = key_source & Trial + @py_assert4 = len(@py_assert3) + @py_assert10 = key_source & restriction + @py_assert11 = len(@py_assert10) + @py_assert6 = @py_assert4 == @py_assert11 + if not @py_assert6: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py12)s\n{%(py12)s = %(py7)s((%(py8)s & %(py9)s))\n}', ), (@py_assert4, @py_assert11)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(key_source) if 'key_source' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key_source) else 'key_source', 'py2':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(key_source) if 'key_source' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key_source) else 'key_source', 'py9':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert10 = @py_assert11 = None + @py_assert3 = key_source - Trial + @py_assert4 = len(@py_assert3) + @py_assert10 = key_source - restriction + @py_assert11 = len(@py_assert10) + @py_assert6 = @py_assert4 == @py_assert11 + if not @py_assert6: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s - %(py2)s))\n} == %(py12)s\n{%(py12)s = %(py7)s((%(py8)s - %(py9)s))\n}', ), (@py_assert4, @py_assert11)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(key_source) if 'key_source' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key_source) else 'key_source', 'py2':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(key_source) if 'key_source' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key_source) else 'key_source', 'py9':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert10 = @py_assert11 = None + @py_assert1 = Ephys() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = 'assert not %(py2)s\n{%(py2)s = %(py0)s()\n}' % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + @py_assert1 = Ephys.Channel + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = 'assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.Channel\n}()\n}' % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + Ephys.populate() + @py_assert1 = Ephys() + if not @py_assert1: + @py_format3 = 'assert %(py2)s\n{%(py2)s = %(py0)s()\n}' % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + @py_assert1 = Ephys.Channel + @py_assert3 = @py_assert1() + if not @py_assert3: + @py_format5 = 'assert %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.Channel\n}()\n}' % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = @py_assert3 = None + + +def test_populate_exclude_error_and_ignore_jobs(schema, Subject, Experiment): + random.seed('populate') + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + @py_assert1 = Experiment() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('table already filled?') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + keys = Experiment.key_source.fetch('KEY', limit=2) + for idx, key in enumerate(keys): + if idx == 0: + schema.jobs.ignore(Experiment.table_name, key) + else: + schema.jobs.error(Experiment.table_name, key, '') + + Experiment.populate(reserve_jobs=True) + @py_assert2 = Experiment.key_source + @py_assert5 = @py_assert2 & Experiment + @py_assert6 = len(@py_assert5) + @py_assert11 = Experiment.key_source + @py_assert13 = len(@py_assert11) + @py_assert15 = 2 + @py_assert17 = @py_assert13 - @py_assert15 + @py_assert8 = @py_assert6 == @py_assert17 + if not @py_assert8: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py0)s((%(py3)s\n{%(py3)s = %(py1)s.key_source\n} & %(py4)s))\n} == (%(py14)s\n{%(py14)s = %(py9)s(%(py12)s\n{%(py12)s = %(py10)s.key_source\n})\n} - %(py16)s)', ), (@py_assert6, @py_assert17)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py10':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py16':@pytest_ar._saferepr(@py_assert15)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert2 = @py_assert5 = @py_assert6 = @py_assert8 = @py_assert11 = @py_assert13 = @py_assert15 = @py_assert17 = None + + +def test_allow_direct_insert(Subject, Experiment): + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + key = Subject().fetch('KEY', limit=1)[0] + key['experiment_id'] = 1000 + key['experiment_date'] = '2018-10-30' + Experiment.insert1(key, allow_direct_insert=True) + + +def test_multi_processing(Subject, Experiment): + random.seed('populate') + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + @py_assert1 = Experiment() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('table already filled?') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + Experiment.populate(processes=2) + @py_assert2 = Experiment() + @py_assert4 = len(@py_assert2) + @py_assert9 = Subject() + @py_assert11 = len(@py_assert9) + @py_assert14 = Experiment.fake_experiments_per_subject + @py_assert16 = @py_assert11 * @py_assert14 + @py_assert6 = @py_assert4 == @py_assert16 + if not @py_assert6: + @py_format17 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == (%(py12)s\n{%(py12)s = %(py7)s(%(py10)s\n{%(py10)s = %(py8)s()\n})\n} * %(py15)s\n{%(py15)s = %(py13)s.fake_experiments_per_subject\n})', ), (@py_assert4, @py_assert16)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py13':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format19 = 'assert %(py18)s' % {'py18': @py_format17} + raise AssertionError(@pytest_ar._format_explanation(@py_format19)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert9 = @py_assert11 = @py_assert14 = @py_assert16 = None + + +def test_max_multi_processing(Subject, Experiment): + random.seed('populate') + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + @py_assert1 = Experiment() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('table already filled?') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + Experiment.populate(processes=None) + @py_assert2 = Experiment() + @py_assert4 = len(@py_assert2) + @py_assert9 = Subject() + @py_assert11 = len(@py_assert9) + @py_assert14 = Experiment.fake_experiments_per_subject + @py_assert16 = @py_assert11 * @py_assert14 + @py_assert6 = @py_assert4 == @py_assert16 + if not @py_assert6: + @py_format17 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == (%(py12)s\n{%(py12)s = %(py7)s(%(py10)s\n{%(py10)s = %(py8)s()\n})\n} * %(py15)s\n{%(py15)s = %(py13)s.fake_experiments_per_subject\n})', ), (@py_assert4, @py_assert16)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py13':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format19 = 'assert %(py18)s' % {'py18': @py_format17} + raise AssertionError(@pytest_ar._format_explanation(@py_format19)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert9 = @py_assert11 = @py_assert14 = @py_assert16 = None + + +def test_allow_insert(Subject, Experiment): + @py_assert1 = Subject() + if not @py_assert1: + @py_format3 = (@pytest_ar._format_assertmsg('root tables are empty') + '\n>assert %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert1 = None + key = Subject().fetch('KEY')[0] + key['experiment_id'] = 1001 + key['experiment_date'] = '2018-10-30' + with pytest.raises(DataJointError): + Experiment.insert1(key) + + +@pytest.fixture +def schema_load_deps(connection_test): + schema_load_deps = dj.Schema((PREFIX + '_load_dependencies_populate'), + connection=connection_test) + yield schema_load_deps + schema_load_deps.drop() + + +@pytest.fixture +def ImageSource(schema_load_deps): + + @schema_load_deps + class ImageSource(dj.Lookup): + definition = '\n image_source_id: int\n ' + contents = [(0, )] + + yield ImageSource + ImageSource.drop() + + +@pytest.fixture +def Image(schema_load_deps, ImageSource): + + @schema_load_deps + class Image(dj.Imported): + definition = '\n -> ImageSource\n ---\n image_data: longblob\n ' + + def make(self, key): + self.insert1(dict(key, image_data=(dict()))) + + yield Image + Image.drop() + + +@pytest.fixture +def Crop(schema_load_deps, Image): + + @schema_load_deps + class Crop(dj.Computed): + definition = '\n -> Image\n ---\n crop_image: longblob\n ' + + def make(self, key): + self.insert1(dict(key, crop_image=(dict()))) + + yield Crop + Crop.drop() + + +def test_load_dependencies(Image, Crop): + Image.populate() + Crop.populate() \ No newline at end of file diff --git a/tests/test_blob.py b/tests/test_blob.py new file mode 100644 index 000000000..25041e6f7 --- /dev/null +++ b/tests/test_blob.py @@ -0,0 +1,456 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_blob.py +# Compiled at: 2023-02-17 22:18:42 +# Size of source mod 2**32: 8131 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from datajoint.blob import pack, unpack +import numpy as np, uuid, timeit +from datetime import datetime +from decimal import Decimal +from numpy.testing import assert_array_equal +import pytest +from . import connection_root, connection_test +from schemas.default import schema, Longblob + +def test_pack(): + np.random.seed(100) + for x in ( + 32, + -0.037, + np.float64(3e+31), + -np.inf, + np.int8(-3), + np.uint8(-1), + np.int16(-33), + np.uint16(-33), + np.int32(-3), + np.uint32(-1), + np.int64(373), + np.uint64(-3)): + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg("Scalars don't match!") + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + else: + @py_assert1 = @py_assert5 = @py_assert7 = None + + x = np.nan + @py_assert1 = np.isnan + @py_assert6 = pack(x) + @py_assert8 = unpack(@py_assert6) + @py_assert10 = @py_assert1(@py_assert8) + if not @py_assert10: + @py_format12 = (@pytest_ar._format_assertmsg('nan scalar did not match!') + '\n>assert %(py11)s\n{%(py11)s = %(py2)s\n{%(py2)s = %(py0)s.isnan\n}(%(py9)s\n{%(py9)s = %(py3)s(%(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n})\n})\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py4':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py5':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10)} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert1 = @py_assert6 = @py_assert8 = @py_assert10 = None + x = np.random.randn(8, 10) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + x = np.random.randn(10) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + x = complex(0.0, 7.0) + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Complex scalar does not match') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = np.float32(np.random.randn(3, 4, 5)) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + x = np.int16(np.random.randn(1, 2, 3)) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + x = None + @py_assert3 = pack(x) + @py_assert5 = unpack(@py_assert3) + @py_assert8 = None + @py_assert7 = @py_assert5 is @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('is', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s(%(py4)s\n{%(py4)s = %(py1)s(%(py2)s)\n})\n} is %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py1':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = (@pytest_ar._format_assertmsg('None did not match') + '\n>assert %(py11)s') % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert3 = @py_assert5 = @py_assert7 = @py_assert8 = None + x = -255 + y = unpack(pack(x)) + @py_assert1 = [] + @py_assert3 = x == y + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert11 = isinstance(y, int) + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert17 = np.ndarray + @py_assert19 = isinstance(y, @py_assert17) + @py_assert21 = not @py_assert19 + @py_assert0 = @py_assert21 + if not @py_assert0: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py4)s', ), (x, y)) % {'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y'} + @py_format7 = '%(py6)s' % {'py6': @py_format5} + @py_assert1.append(@py_format7) + if @py_assert3: + @py_format13 = '%(py12)s\n{%(py12)s = %(py8)s(%(py9)s, %(py10)s)\n}' % {'py8':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py9':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py10':@pytest_ar._saferepr(int) if 'int' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(int) else 'int', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format22 = 'not %(py20)s\n{%(py20)s = %(py14)s(%(py15)s, %(py18)s\n{%(py18)s = %(py16)s.ndarray\n})\n}' % {'py14':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py15':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py16':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py18':@pytest_ar._saferepr(@py_assert17), 'py20':@pytest_ar._saferepr(@py_assert19)} + @py_assert1.append(@py_format22) + @py_format23 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format25 = (@pytest_ar._format_assertmsg('Scalar int did not match') + '\n>assert %(py24)s') % {'py24': @py_format23} + raise AssertionError(@pytest_ar._format_explanation(@py_format25)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert11 = @py_assert17 = @py_assert19 = @py_assert21 = None + x = -25523987234234287910987234987098245697129798713407812347 + y = unpack(pack(x)) + @py_assert1 = [] + @py_assert3 = x == y + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert11 = isinstance(y, int) + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert17 = np.ndarray + @py_assert19 = isinstance(y, @py_assert17) + @py_assert21 = not @py_assert19 + @py_assert0 = @py_assert21 + if not @py_assert0: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py4)s', ), (x, y)) % {'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y'} + @py_format7 = '%(py6)s' % {'py6': @py_format5} + @py_assert1.append(@py_format7) + if @py_assert3: + @py_format13 = '%(py12)s\n{%(py12)s = %(py8)s(%(py9)s, %(py10)s)\n}' % {'py8':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py9':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py10':@pytest_ar._saferepr(int) if 'int' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(int) else 'int', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format22 = 'not %(py20)s\n{%(py20)s = %(py14)s(%(py15)s, %(py18)s\n{%(py18)s = %(py16)s.ndarray\n})\n}' % {'py14':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py15':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py16':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py18':@pytest_ar._saferepr(@py_assert17), 'py20':@pytest_ar._saferepr(@py_assert19)} + @py_assert1.append(@py_format22) + @py_format23 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format25 = (@pytest_ar._format_assertmsg('Unbounded int did not match') + '\n>assert %(py24)s') % {'py24': @py_format23} + raise AssertionError(@pytest_ar._format_explanation(@py_format25)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert11 = @py_assert17 = @py_assert19 = @py_assert21 = None + x = 7.0 + y = unpack(pack(x)) + @py_assert1 = [] + @py_assert3 = x == y + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert11 = isinstance(y, float) + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert17 = np.ndarray + @py_assert19 = isinstance(y, @py_assert17) + @py_assert21 = not @py_assert19 + @py_assert0 = @py_assert21 + if not @py_assert0: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py4)s', ), (x, y)) % {'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y'} + @py_format7 = '%(py6)s' % {'py6': @py_format5} + @py_assert1.append(@py_format7) + if @py_assert3: + @py_format13 = '%(py12)s\n{%(py12)s = %(py8)s(%(py9)s, %(py10)s)\n}' % {'py8':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py9':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py10':@pytest_ar._saferepr(float) if 'float' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(float) else 'float', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format22 = 'not %(py20)s\n{%(py20)s = %(py14)s(%(py15)s, %(py18)s\n{%(py18)s = %(py16)s.ndarray\n})\n}' % {'py14':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py15':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py16':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py18':@pytest_ar._saferepr(@py_assert17), 'py20':@pytest_ar._saferepr(@py_assert19)} + @py_assert1.append(@py_format22) + @py_format23 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format25 = (@pytest_ar._format_assertmsg('Scalar float did not match') + '\n>assert %(py24)s') % {'py24': @py_format23} + raise AssertionError(@pytest_ar._format_explanation(@py_format25)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert11 = @py_assert17 = @py_assert19 = @py_assert21 = None + x = complex(0.0, 7.0) + y = unpack(pack(x)) + @py_assert1 = [] + @py_assert3 = x == y + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert11 = isinstance(y, complex) + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert17 = np.ndarray + @py_assert19 = isinstance(y, @py_assert17) + @py_assert21 = not @py_assert19 + @py_assert0 = @py_assert21 + if not @py_assert0: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py4)s', ), (x, y)) % {'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y'} + @py_format7 = '%(py6)s' % {'py6': @py_format5} + @py_assert1.append(@py_format7) + if @py_assert3: + @py_format13 = '%(py12)s\n{%(py12)s = %(py8)s(%(py9)s, %(py10)s)\n}' % {'py8':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py9':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py10':@pytest_ar._saferepr(complex) if 'complex' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(complex) else 'complex', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format22 = 'not %(py20)s\n{%(py20)s = %(py14)s(%(py15)s, %(py18)s\n{%(py18)s = %(py16)s.ndarray\n})\n}' % {'py14':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py15':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y', 'py16':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py18':@pytest_ar._saferepr(@py_assert17), 'py20':@pytest_ar._saferepr(@py_assert19)} + @py_assert1.append(@py_format22) + @py_format23 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format25 = (@pytest_ar._format_assertmsg('Complex scalar did not match') + '\n>assert %(py24)s') % {'py24': @py_format23} + raise AssertionError(@pytest_ar._format_explanation(@py_format25)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert11 = @py_assert17 = @py_assert19 = @py_assert21 = None + x = True + @py_assert3 = pack(x) + @py_assert5 = unpack(@py_assert3) + @py_assert8 = True + @py_assert7 = @py_assert5 is @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('is', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s(%(py4)s\n{%(py4)s = %(py1)s(%(py2)s)\n})\n} is %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py1':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py2':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = (@pytest_ar._format_assertmsg('Scalar bool did not match') + '\n>assert %(py11)s') % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert3 = @py_assert5 = @py_assert7 = @py_assert8 = None + x = [ + None] + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = {'name':'Anonymous', + 'age':15, + 99:datetime.now(), + 'range':[ + 110, 190], + (11, 12):None} + y = unpack(pack(x)) + @py_assert1 = x == y + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (x, y)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(y) if 'y' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(y) else 'y'} + @py_format5 = (@pytest_ar._format_assertmsg('Dict do not match!') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + @py_assert1 = ['range'][0] + @py_assert4 = np.ndarray + @py_assert6 = isinstance(@py_assert1, @py_assert4) + @py_assert8 = not @py_assert6 + if not @py_assert8: + @py_format9 = (@pytest_ar._format_assertmsg('Scalar int was coerced into arrray.') + '\n>assert not %(py7)s\n{%(py7)s = %(py0)s(%(py2)s, %(py5)s\n{%(py5)s = %(py3)s.ndarray\n})\n}') % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert4 = @py_assert6 = @py_assert8 = None + x = uuid.uuid4() + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('UUID did not match') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = Decimal('-112122121.000003000') + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Decimal did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = [ + 1, datetime.now(), {1:'one', 'two':2}, (1, 2)] + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('List did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = ( + 1, datetime.now(), {1:'one', 'two':2}, (uuid.uuid4(), 2)) + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Tuple did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = ( + 1, + {datetime.now().date(): 'today', 'now': datetime.now().date()}, + {'yes!': [1, 2, np.array((3, 4))]}) + y = unpack(pack(x)) + @py_assert0 = x[1] + @py_assert3 = y[1] + @py_assert2 = @py_assert0 == @py_assert3 + if not @py_assert2: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert2,), ('%(py1)s == %(py4)s', ), (@py_assert0, @py_assert3)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert0 = @py_assert2 = @py_assert3 = None + assert_array_equal(x[2]['yes!'][2], y[2]['yes!'][2]) + x = { + 'elephant'} + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Set did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = tuple(range(10)) + @py_assert5 = 10 + @py_assert7 = range(@py_assert5) + @py_assert9 = pack(@py_assert7) + @py_assert11 = unpack(@py_assert9) + @py_assert1 = x == @py_assert11 + if not @py_assert1: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py12)s\n{%(py12)s = %(py2)s(%(py10)s\n{%(py10)s = %(py3)s(%(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n})\n})\n}', ), (x, @py_assert11)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(range) if 'range' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(range) else 'range', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('Iterator did not pack/unpack correctly') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = None + x = Decimal('1.24') + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Decimal object did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = datetime.now() + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Datetime object did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = np.bool_(True) + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Numpy bool object did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = 'test' + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('String object did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = np.array(['yes']) + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Numpy string array object did not pack/unpack correctly') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + x = np.datetime64('1998').astype('datetime64[us]') + @py_assert5 = pack(x) + @py_assert7 = unpack(@py_assert5) + @py_assert1 = x == @py_assert7 + if not @py_assert1: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py8)s\n{%(py8)s = %(py2)s(%(py6)s\n{%(py6)s = %(py3)s(%(py4)s)\n})\n}', ), (x, @py_assert7)) % {'py0':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py2':@pytest_ar._saferepr(unpack) if 'unpack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unpack) else 'unpack', 'py3':@pytest_ar._saferepr(pack) if 'pack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pack) else 'pack', 'py4':@pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert5 = @py_assert7 = None + + +def test_recarrays(): + x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)]) + assert_array_equal(x, unpack(pack(x))) + x = x.view(np.recarray) + assert_array_equal(x, unpack(pack(x))) + x = np.array([(3, 4)], dtype=[('tmp0', float), ('tmp1', 'O')]).view(np.recarray) + assert_array_equal(x, unpack(pack(x))) + + +def test_object_arrays(): + x = np.array(((1, 2, 3), True), dtype='object') + assert_array_equal(x, unpack(pack(x)), 'Object array did not serialize correctly') + + +def test_complex(): + np.random.seed(100) + z = np.random.randn(8, 10) + complex(0.0, 1.0) * np.random.randn(8, 10) + assert_array_equal(z, unpack(pack(z)), 'Arrays do not match!') + z = np.random.randn(10) + complex(0.0, 1.0) * np.random.randn(10) + assert_array_equal(z, unpack(pack(z)), 'Arrays do not match!') + x = np.float32(np.random.randn(3, 4, 5)) + complex(0.0, 1.0) * np.float32(np.random.randn(3, 4, 5)) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + x = np.int16(np.random.randn(1, 2, 3)) + complex(0.0, 1.0) * np.int16(np.random.randn(1, 2, 3)) + assert_array_equal(x, unpack(pack(x)), 'Arrays do not match!') + + +insert_dj_blob = {'id':3, + 'data':[1, 2, 3]} +query_mym_blob = {'id':2, 'data':np.array([1, 2, 3])} + +@pytest.fixture +def LongblobWithData(Longblob): + Longblob.insert1(insert_dj_blob) + Longblob.insert1(query_mym_blob) + yield Longblob + Longblob.delete() + + +def test_insert_longblob(LongblobWithData): + @py_assert1 = 'id=3' + @py_assert3 = LongblobWithData & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = @py_assert4() + @py_assert8 = @py_assert6 == insert_dj_blob + if not @py_assert8: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}()\n} == %(py9)s', ), (@py_assert6, insert_dj_blob)) % {'py0':@pytest_ar._saferepr(LongblobWithData) if 'LongblobWithData' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(LongblobWithData) else 'LongblobWithData', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(insert_dj_blob) if 'insert_dj_blob' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(insert_dj_blob) else 'insert_dj_blob'} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = None + assert_array_equal((LongblobWithData & 'id=2').fetch1()['data'], query_mym_blob['data']) + + +@pytest.fixture +def LongblobWith32BitData(schema, Longblob): + query_32_blob = "INSERT INTO djtest_test1.longblob (id, data) VALUES (1, X'6D596D00530200000001000000010000000400000068697473007369646573007461736B73007374616765004D000000410200000001000000070000000600000000000000000000000000F8FF000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000F8FF230000004102000000010000000700000004000000000000006C006C006C006C00720072006C002300000041020000000100000007000000040000000000000064006400640064006400640064002500000041020000000100000008000000040000000000000053007400610067006500200031003000')" + schema.connection.query(query_32_blob) + dj.blob.use_32bit_dims = True + yield Longblob + dj.blob.use_32bit_dims = False + Longblob.delete() + + +def test_insert_longblob_32bit(LongblobWith32BitData): + expected = np.rec.array([ + [ + ( + np.array([[np.nan, 1.0, 1.0, 0.0, 1.0, 0.0, np.nan]]), + np.array(['llllrrl'], dtype='assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + @py_assert1 = [] + @py_assert3 = L() + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert7 = A() + @py_assert0 = @py_assert7 + if @py_assert7: + @py_assert11 = B() + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert15 = B.C + @py_assert17 = @py_assert15() + @py_assert0 = @py_assert17 + if @py_assert17: + @py_assert21 = D() + @py_assert0 = @py_assert21 + if @py_assert21: + @py_assert25 = E() + @py_assert0 = @py_assert25 + if @py_assert25: + @py_assert29 = E.F + @py_assert31 = @py_assert29() + @py_assert0 = @py_assert31 + if not @py_assert0: + @py_format5 = '%(py4)s\n{%(py4)s = %(py2)s()\n}' % {'py2':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_assert1.append(@py_format5) + if @py_assert3: + @py_format9 = '%(py8)s\n{%(py8)s = %(py6)s()\n}' % {'py6':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_assert1.append(@py_format9) + if @py_assert7: + @py_format13 = '%(py12)s\n{%(py12)s = %(py10)s()\n}' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format19 = '%(py18)s\n{%(py18)s = %(py16)s\n{%(py16)s = %(py14)s.C\n}()\n}' % {'py14':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_assert1.append(@py_format19) + if @py_assert17: + @py_format23 = '%(py22)s\n{%(py22)s = %(py20)s()\n}' % {'py20':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py22':@pytest_ar._saferepr(@py_assert21)} + @py_assert1.append(@py_format23) + if @py_assert21: + @py_format27 = '%(py26)s\n{%(py26)s = %(py24)s()\n}' % {'py24':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py26':@pytest_ar._saferepr(@py_assert25)} + @py_assert1.append(@py_format27) + if @py_assert25: + @py_format33 = '%(py32)s\n{%(py32)s = %(py30)s\n{%(py30)s = %(py28)s.F\n}()\n}' % {'py28':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py30':@pytest_ar._saferepr(@py_assert29), 'py32':@pytest_ar._saferepr(@py_assert31)} + @py_assert1.append(@py_format33) + @py_format34 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format36 = (@pytest_ar._format_assertmsg('schema is not populated') + '\n>assert %(py35)s') % {'py35': @py_format34} + raise AssertionError(@pytest_ar._format_explanation(@py_format36)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert7 = @py_assert11 = @py_assert15 = @py_assert17 = @py_assert21 = @py_assert25 = @py_assert29 = @py_assert31 = None + A().delete() + @py_assert1 = [] + @py_assert3 = A() + @py_assert0 = @py_assert3 + if not @py_assert3: + @py_assert7 = B() + @py_assert0 = @py_assert7 + if not @py_assert7: + @py_assert11 = B.C + @py_assert13 = @py_assert11() + @py_assert0 = @py_assert13 + if not @py_assert13: + @py_assert17 = D() + @py_assert0 = @py_assert17 + if not @py_assert17: + @py_assert21 = E() + @py_assert0 = @py_assert21 + if not @py_assert21: + @py_assert25 = E.F + @py_assert27 = @py_assert25() + @py_assert0 = @py_assert27 + @py_assert32 = not @py_assert0 + if not @py_assert32: + @py_format5 = '%(py4)s\n{%(py4)s = %(py2)s()\n}' % {'py2':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_assert1.append(@py_format5) + if not @py_assert3: + @py_format9 = '%(py8)s\n{%(py8)s = %(py6)s()\n}' % {'py6':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_assert1.append(@py_format9) + if not @py_assert7: + @py_format15 = '%(py14)s\n{%(py14)s = %(py12)s\n{%(py12)s = %(py10)s.C\n}()\n}' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13)} + @py_assert1.append(@py_format15) + if not @py_assert13: + @py_format19 = '%(py18)s\n{%(py18)s = %(py16)s()\n}' % {'py16':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_assert1.append(@py_format19) + if not @py_assert17: + @py_format23 = '%(py22)s\n{%(py22)s = %(py20)s()\n}' % {'py20':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py22':@pytest_ar._saferepr(@py_assert21)} + @py_assert1.append(@py_format23) + if not @py_assert21: + @py_format29 = '%(py28)s\n{%(py28)s = %(py26)s\n{%(py26)s = %(py24)s.F\n}()\n}' % {'py24':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py26':@pytest_ar._saferepr(@py_assert25), 'py28':@pytest_ar._saferepr(@py_assert27)} + @py_assert1.append(@py_format29) + @py_format30 = @pytest_ar._format_boolop(@py_assert1, 1) % {} + @py_format33 = (@pytest_ar._format_assertmsg('incomplete delete') + '\n>assert not %(py31)s') % {'py31': @py_format30} + raise AssertionError(@pytest_ar._format_explanation(@py_format33)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert7 = @py_assert11 = @py_assert13 = @py_assert17 = @py_assert21 = @py_assert25 = @py_assert27 = @py_assert32 = None + + +def test_stepwise_delete(L, A, B): + random.seed('cascade') + B().populate() + @py_assert0 = dj.config['safemode'] + @py_assert2 = not @py_assert0 + if not @py_assert2: + @py_format3 = (@pytest_ar._format_assertmsg('safemode must be off for testing') + '\n>assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + @py_assert1 = [] + @py_assert3 = L() + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert7 = A() + @py_assert0 = @py_assert7 + if @py_assert7: + @py_assert11 = B() + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert15 = B.C + @py_assert17 = @py_assert15() + @py_assert0 = @py_assert17 + if not @py_assert0: + @py_format5 = '%(py4)s\n{%(py4)s = %(py2)s()\n}' % {'py2':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_assert1.append(@py_format5) + if @py_assert3: + @py_format9 = '%(py8)s\n{%(py8)s = %(py6)s()\n}' % {'py6':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_assert1.append(@py_format9) + if @py_assert7: + @py_format13 = '%(py12)s\n{%(py12)s = %(py10)s()\n}' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format19 = '%(py18)s\n{%(py18)s = %(py16)s\n{%(py16)s = %(py14)s.C\n}()\n}' % {'py14':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_assert1.append(@py_format19) + @py_format20 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format22 = (@pytest_ar._format_assertmsg('schema population failed') + '\n>assert %(py21)s') % {'py21': @py_format20} + raise AssertionError(@pytest_ar._format_explanation(@py_format22)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert7 = @py_assert11 = @py_assert15 = @py_assert17 = None + B.C().delete(force=True) + @py_assert1 = B.C + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = (@pytest_ar._format_assertmsg('failed to delete child tables') + '\n>assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.C\n}()\n}') % {'py0':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + B().delete() + @py_assert1 = B() + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('failed to delete from the parent table following child table deletion') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s()\n}') % {'py0':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + + +def test_delete_tree_restricted(L, A, B, D, E): + random.seed('cascade') + B().populate() + D().populate() + E().populate() + @py_assert0 = dj.config['safemode'] + @py_assert2 = not @py_assert0 + if not @py_assert2: + @py_format3 = (@pytest_ar._format_assertmsg('safemode must be off for testing') + '\n>assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + @py_assert1 = [] + @py_assert3 = L() + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert7 = A() + @py_assert0 = @py_assert7 + if @py_assert7: + @py_assert11 = B() + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert15 = B.C + @py_assert17 = @py_assert15() + @py_assert0 = @py_assert17 + if @py_assert17: + @py_assert21 = D() + @py_assert0 = @py_assert21 + if @py_assert21: + @py_assert25 = E() + @py_assert0 = @py_assert25 + if @py_assert25: + @py_assert29 = E.F + @py_assert31 = @py_assert29() + @py_assert0 = @py_assert31 + if not @py_assert0: + @py_format5 = '%(py4)s\n{%(py4)s = %(py2)s()\n}' % {'py2':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_assert1.append(@py_format5) + if @py_assert3: + @py_format9 = '%(py8)s\n{%(py8)s = %(py6)s()\n}' % {'py6':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_assert1.append(@py_format9) + if @py_assert7: + @py_format13 = '%(py12)s\n{%(py12)s = %(py10)s()\n}' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format19 = '%(py18)s\n{%(py18)s = %(py16)s\n{%(py16)s = %(py14)s.C\n}()\n}' % {'py14':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_assert1.append(@py_format19) + if @py_assert17: + @py_format23 = '%(py22)s\n{%(py22)s = %(py20)s()\n}' % {'py20':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py22':@pytest_ar._saferepr(@py_assert21)} + @py_assert1.append(@py_format23) + if @py_assert21: + @py_format27 = '%(py26)s\n{%(py26)s = %(py24)s()\n}' % {'py24':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py26':@pytest_ar._saferepr(@py_assert25)} + @py_assert1.append(@py_format27) + if @py_assert25: + @py_format33 = '%(py32)s\n{%(py32)s = %(py30)s\n{%(py30)s = %(py28)s.F\n}()\n}' % {'py28':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py30':@pytest_ar._saferepr(@py_assert29), 'py32':@pytest_ar._saferepr(@py_assert31)} + @py_assert1.append(@py_format33) + @py_format34 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format36 = (@pytest_ar._format_assertmsg('schema is not populated') + '\n>assert %(py35)s') % {'py35': @py_format34} + raise AssertionError(@pytest_ar._format_explanation(@py_format36)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert7 = @py_assert11 = @py_assert15 = @py_assert17 = @py_assert21 = @py_assert25 = @py_assert29 = @py_assert31 = None + cond = 'cond_in_a' + rel = A() & cond + rest = dict(A=(len(A()) - len(rel)), + B=(len(B() - rel)), + C=(len(B.C() - rel)), + D=(len(D() - rel)), + E=(len(E() - rel)), + F=(len(E.F() - rel))) + rel.delete() + @py_assert1 = [] + @py_assert0 = rel + if not rel: + @py_assert5 = B() + @py_assert8 = @py_assert5 & rel + @py_assert0 = @py_assert8 + if not @py_assert8: + @py_assert11 = B.C + @py_assert13 = @py_assert11() + @py_assert16 = @py_assert13 & rel + @py_assert0 = @py_assert16 + if not @py_assert16: + @py_assert19 = D() + @py_assert22 = @py_assert19 & rel + @py_assert0 = @py_assert22 + if not @py_assert22: + @py_assert25 = E() + @py_assert28 = @py_assert25 & rel + @py_assert0 = @py_assert28 + if not @py_assert28: + @py_assert31 = E.F + @py_assert33 = @py_assert31() + @py_assert36 = @py_assert33 & rel + @py_assert0 = @py_assert36 + @py_assert40 = not @py_assert0 + if not @py_assert40: + @py_format3 = '%(py2)s' % {'py2': @pytest_ar._saferepr(rel) if ('rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel)) else 'rel'} + @py_assert1.append(@py_format3) + if not rel: + @py_format9 = '(%(py6)s\n{%(py6)s = %(py4)s()\n} & %(py7)s)' % {'py4':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py6':@pytest_ar._saferepr(@py_assert5), 'py7':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel'} + @py_assert1.append(@py_format9) + if not @py_assert8: + @py_format17 = '(%(py14)s\n{%(py14)s = %(py12)s\n{%(py12)s = %(py10)s.C\n}()\n} & %(py15)s)' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py15':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel'} + @py_assert1.append(@py_format17) + if not @py_assert16: + @py_format23 = '(%(py20)s\n{%(py20)s = %(py18)s()\n} & %(py21)s)' % {'py18':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py20':@pytest_ar._saferepr(@py_assert19), 'py21':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel'} + @py_assert1.append(@py_format23) + if not @py_assert22: + @py_format29 = '(%(py26)s\n{%(py26)s = %(py24)s()\n} & %(py27)s)' % {'py24':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py26':@pytest_ar._saferepr(@py_assert25), 'py27':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel'} + @py_assert1.append(@py_format29) + if not @py_assert28: + @py_format37 = '(%(py34)s\n{%(py34)s = %(py32)s\n{%(py32)s = %(py30)s.F\n}()\n} & %(py35)s)' % {'py30':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py32':@pytest_ar._saferepr(@py_assert31), 'py34':@pytest_ar._saferepr(@py_assert33), 'py35':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel'} + @py_assert1.append(@py_format37) + @py_format38 = @pytest_ar._format_boolop(@py_assert1, 1) % {} + @py_format41 = (@pytest_ar._format_assertmsg('incomplete delete') + '\n>assert not %(py39)s') % {'py39': @py_format38} + raise AssertionError(@pytest_ar._format_explanation(@py_format41)) + @py_assert0 = @py_assert1 = @py_assert5 = @py_assert8 = @py_assert11 = @py_assert13 = @py_assert16 = @py_assert19 = @py_assert22 = @py_assert25 = @py_assert28 = @py_assert31 = @py_assert33 = @py_assert36 = @py_assert40 = None + @py_assert2 = A() + @py_assert4 = len(@py_assert2) + @py_assert7 = rest['A'] + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert2 = B() + @py_assert4 = len(@py_assert2) + @py_assert7 = rest['B'] + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert2 = B.C + @py_assert4 = @py_assert2() + @py_assert6 = len(@py_assert4) + @py_assert9 = rest['C'] + @py_assert8 = @py_assert6 == @py_assert9 + if not @py_assert8: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py0)s(%(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s.C\n}()\n})\n} == %(py10)s', ), (@py_assert6, @py_assert9)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py12)s') % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert9 = None + @py_assert2 = D() + @py_assert4 = len(@py_assert2) + @py_assert7 = rest['D'] + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert2 = E() + @py_assert4 = len(@py_assert2) + @py_assert7 = rest['E'] + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert2 = E.F + @py_assert4 = @py_assert2() + @py_assert6 = len(@py_assert4) + @py_assert9 = rest['F'] + @py_assert8 = @py_assert6 == @py_assert9 + if not @py_assert8: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py0)s(%(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s.F\n}()\n})\n} == %(py10)s', ), (@py_assert6, @py_assert9)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = (@pytest_ar._format_assertmsg('invalid delete restriction') + '\n>assert %(py12)s') % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert9 = None + + +def test_delete_lookup(L, A, B, D, E): + random.seed('cascade') + B().populate() + D().populate() + E().populate() + @py_assert0 = dj.config['safemode'] + @py_assert2 = not @py_assert0 + if not @py_assert2: + @py_format3 = (@pytest_ar._format_assertmsg('safemode must be off for testing') + '\n>assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + @py_assert2 = [] + @py_assert4 = L() + @py_assert1 = @py_assert4 + if @py_assert4: + @py_assert8 = A() + @py_assert1 = @py_assert8 + if @py_assert8: + @py_assert12 = B() + @py_assert1 = @py_assert12 + if @py_assert12: + @py_assert16 = B.C + @py_assert18 = @py_assert16() + @py_assert1 = @py_assert18 + if @py_assert18: + @py_assert22 = D() + @py_assert1 = @py_assert22 + if @py_assert22: + @py_assert26 = E() + @py_assert1 = @py_assert26 + if @py_assert26: + @py_assert30 = E.F + @py_assert32 = @py_assert30() + @py_assert1 = @py_assert32 + @py_assert37 = bool(@py_assert1) + if not @py_assert37: + @py_format6 = '%(py5)s\n{%(py5)s = %(py3)s()\n}' % {'py3':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_assert2.append(@py_format6) + if @py_assert4: + @py_format10 = '%(py9)s\n{%(py9)s = %(py7)s()\n}' % {'py7':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_assert2.append(@py_format10) + if @py_assert8: + @py_format14 = '%(py13)s\n{%(py13)s = %(py11)s()\n}' % {'py11':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py13':@pytest_ar._saferepr(@py_assert12)} + @py_assert2.append(@py_format14) + if @py_assert12: + @py_format20 = '%(py19)s\n{%(py19)s = %(py17)s\n{%(py17)s = %(py15)s.C\n}()\n}' % {'py15':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py17':@pytest_ar._saferepr(@py_assert16), 'py19':@pytest_ar._saferepr(@py_assert18)} + @py_assert2.append(@py_format20) + if @py_assert18: + @py_format24 = '%(py23)s\n{%(py23)s = %(py21)s()\n}' % {'py21':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py23':@pytest_ar._saferepr(@py_assert22)} + @py_assert2.append(@py_format24) + if @py_assert22: + @py_format28 = '%(py27)s\n{%(py27)s = %(py25)s()\n}' % {'py25':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py27':@pytest_ar._saferepr(@py_assert26)} + @py_assert2.append(@py_format28) + if @py_assert26: + @py_format34 = '%(py33)s\n{%(py33)s = %(py31)s\n{%(py31)s = %(py29)s.F\n}()\n}' % {'py29':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py31':@pytest_ar._saferepr(@py_assert30), 'py33':@pytest_ar._saferepr(@py_assert32)} + @py_assert2.append(@py_format34) + @py_format35 = @pytest_ar._format_boolop(@py_assert2, 0) % {} + @py_format39 = (@pytest_ar._format_assertmsg('schema is not populated') + '\n>assert %(py38)s\n{%(py38)s = %(py0)s(%(py36)s)\n}') % {'py0':@pytest_ar._saferepr(bool) if 'bool' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(bool) else 'bool', 'py36':@py_format35, 'py38':@pytest_ar._saferepr(@py_assert37)} + raise AssertionError(@pytest_ar._format_explanation(@py_format39)) + @py_assert1 = @py_assert2 = @py_assert4 = @py_assert8 = @py_assert12 = @py_assert16 = @py_assert18 = @py_assert22 = @py_assert26 = @py_assert30 = @py_assert32 = @py_assert37 = None + L().delete() + @py_assert2 = [] + @py_assert4 = L() + @py_assert1 = @py_assert4 + if not @py_assert4: + @py_assert8 = D() + @py_assert1 = @py_assert8 + if not @py_assert8: + @py_assert12 = E() + @py_assert1 = @py_assert12 + if not @py_assert12: + @py_assert16 = E.F + @py_assert18 = @py_assert16() + @py_assert1 = @py_assert18 + @py_assert23 = bool(@py_assert1) + @py_assert25 = not @py_assert23 + if not @py_assert25: + @py_format6 = '%(py5)s\n{%(py5)s = %(py3)s()\n}' % {'py3':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_assert2.append(@py_format6) + if not @py_assert4: + @py_format10 = '%(py9)s\n{%(py9)s = %(py7)s()\n}' % {'py7':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_assert2.append(@py_format10) + if not @py_assert8: + @py_format14 = '%(py13)s\n{%(py13)s = %(py11)s()\n}' % {'py11':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py13':@pytest_ar._saferepr(@py_assert12)} + @py_assert2.append(@py_format14) + if not @py_assert12: + @py_format20 = '%(py19)s\n{%(py19)s = %(py17)s\n{%(py17)s = %(py15)s.F\n}()\n}' % {'py15':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py17':@pytest_ar._saferepr(@py_assert16), 'py19':@pytest_ar._saferepr(@py_assert18)} + @py_assert2.append(@py_format20) + @py_format21 = @pytest_ar._format_boolop(@py_assert2, 1) % {} + @py_format26 = (@pytest_ar._format_assertmsg('incomplete delete') + '\n>assert not %(py24)s\n{%(py24)s = %(py0)s(%(py22)s)\n}') % {'py0':@pytest_ar._saferepr(bool) if 'bool' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(bool) else 'bool', 'py22':@py_format21, 'py24':@pytest_ar._saferepr(@py_assert23)} + raise AssertionError(@pytest_ar._format_explanation(@py_format26)) + @py_assert1 = @py_assert2 = @py_assert4 = @py_assert8 = @py_assert12 = @py_assert16 = @py_assert18 = @py_assert23 = @py_assert25 = None + A().delete() + + +def test_delete_lookup_restricted(L, A, B, D, E): + random.seed('cascade') + B().populate() + D().populate() + E().populate() + @py_assert0 = dj.config['safemode'] + @py_assert2 = not @py_assert0 + if not @py_assert2: + @py_format3 = (@pytest_ar._format_assertmsg('safemode must be off for testing') + '\n>assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + @py_assert1 = [] + @py_assert3 = L() + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert7 = A() + @py_assert0 = @py_assert7 + if @py_assert7: + @py_assert11 = B() + @py_assert0 = @py_assert11 + if @py_assert11: + @py_assert15 = B.C + @py_assert17 = @py_assert15() + @py_assert0 = @py_assert17 + if @py_assert17: + @py_assert21 = D() + @py_assert0 = @py_assert21 + if @py_assert21: + @py_assert25 = E() + @py_assert0 = @py_assert25 + if @py_assert25: + @py_assert29 = E.F + @py_assert31 = @py_assert29() + @py_assert0 = @py_assert31 + if not @py_assert0: + @py_format5 = '%(py4)s\n{%(py4)s = %(py2)s()\n}' % {'py2':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_assert1.append(@py_format5) + if @py_assert3: + @py_format9 = '%(py8)s\n{%(py8)s = %(py6)s()\n}' % {'py6':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_assert1.append(@py_format9) + if @py_assert7: + @py_format13 = '%(py12)s\n{%(py12)s = %(py10)s()\n}' % {'py10':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_assert1.append(@py_format13) + if @py_assert11: + @py_format19 = '%(py18)s\n{%(py18)s = %(py16)s\n{%(py16)s = %(py14)s.C\n}()\n}' % {'py14':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_assert1.append(@py_format19) + if @py_assert17: + @py_format23 = '%(py22)s\n{%(py22)s = %(py20)s()\n}' % {'py20':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py22':@pytest_ar._saferepr(@py_assert21)} + @py_assert1.append(@py_format23) + if @py_assert21: + @py_format27 = '%(py26)s\n{%(py26)s = %(py24)s()\n}' % {'py24':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py26':@pytest_ar._saferepr(@py_assert25)} + @py_assert1.append(@py_format27) + if @py_assert25: + @py_format33 = '%(py32)s\n{%(py32)s = %(py30)s\n{%(py30)s = %(py28)s.F\n}()\n}' % {'py28':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py30':@pytest_ar._saferepr(@py_assert29), 'py32':@pytest_ar._saferepr(@py_assert31)} + @py_assert1.append(@py_format33) + @py_format34 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format36 = (@pytest_ar._format_assertmsg('schema is not populated') + '\n>assert %(py35)s') % {'py35': @py_format34} + raise AssertionError(@pytest_ar._format_explanation(@py_format36)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert7 = @py_assert11 = @py_assert15 = @py_assert17 = @py_assert21 = @py_assert25 = @py_assert29 = @py_assert31 = None + rel = L() & 'cond_in_l' + original_count = len(L()) + deleted_count = len(rel) + rel.delete() + @py_assert2 = L() + @py_assert4 = len(@py_assert2) + @py_assert9 = original_count - deleted_count + @py_assert6 = @py_assert4 == @py_assert9 + if not @py_assert6: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == (%(py7)s - %(py8)s)', ), (@py_assert4, @py_assert9)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(original_count) if 'original_count' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_count) else 'original_count', 'py8':@pytest_ar._saferepr(deleted_count) if 'deleted_count' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(deleted_count) else 'deleted_count'} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert9 = None + + +def test_delete_complex_keys(ComplexParent, ComplexChild): + @py_assert0 = dj.config['safemode'] + @py_assert2 = not @py_assert0 + if not @py_assert2: + @py_format3 = (@pytest_ar._format_assertmsg('safemode must be off for testing') + '\n>assert not %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format3)) + @py_assert0 = @py_assert2 = None + parent_key_count = 8 + child_key_count = 1 + restriction = dict( + {'parent_id_{}'.format(i + 1): i for i in range(parent_key_count)}, **) + @py_assert3 = ComplexParent & restriction + @py_assert4 = len(@py_assert3) + @py_assert7 = 1 + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(ComplexParent) if 'ComplexParent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ComplexParent) else 'ComplexParent', 'py2':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Parent record missing') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert3 = ComplexChild & restriction + @py_assert4 = len(@py_assert3) + @py_assert7 = 1 + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(ComplexChild) if 'ComplexChild' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ComplexChild) else 'ComplexChild', 'py2':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Child record missing') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert7 = None + (ComplexParent & restriction).delete() + @py_assert3 = ComplexParent & restriction + @py_assert4 = len(@py_assert3) + @py_assert7 = 0 + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(ComplexParent) if 'ComplexParent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ComplexParent) else 'ComplexParent', 'py2':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Parent record was not deleted') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert7 = None + @py_assert3 = ComplexChild & restriction + @py_assert4 = len(@py_assert3) + @py_assert7 = 0 + @py_assert6 = @py_assert4 == @py_assert7 + if not @py_assert6: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s((%(py1)s & %(py2)s))\n} == %(py8)s', ), (@py_assert4, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(ComplexChild) if 'ComplexChild' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ComplexChild) else 'ComplexChild', 'py2':@pytest_ar._saferepr(restriction) if 'restriction' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restriction) else 'restriction', 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = (@pytest_ar._format_assertmsg('Child record was not deleted') + '\n>assert %(py10)s') % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert3 = @py_assert4 = @py_assert6 = @py_assert7 = None + + +def test_delete_master(Profile): + Profile().populate_random() + Profile().delete() + + +def test_delete_parts(Profile, Website): + """test issue #151""" + Profile().populate_random() + with pytest.raises(DataJointError): + Website().delete() + + +def test_drop_part(Profile, Website): + """test issue #374""" + with pytest.raises(DataJointError): + Website().drop() \ No newline at end of file diff --git a/tests/test_declare.py b/tests/test_declare.py new file mode 100644 index 000000000..dfaccb3c4 --- /dev/null +++ b/tests/test_declare.py @@ -0,0 +1,636 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_declare.py +# Compiled at: 2023-02-18 19:51:35 +# Size of source mod 2**32: 9386 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +import datajoint.declare as declare +import pytest +from . import connection_root, connection_test +from schemas.default import schema, Subject, TTest, TTest2, User, Experiment, IndexRich, ThingC, ThingA, ThingB, Auto, Trial, Ephys + +def test_schema_decorator(Subject): + @py_assert3 = dj.Lookup + @py_assert5 = issubclass(Subject, @py_assert3) + if not @py_assert5: + @py_format7 = 'assert %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.Lookup\n})\n}' % {'py0':@pytest_ar._saferepr(issubclass) if 'issubclass' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(issubclass) else 'issubclass', 'py1':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert3 = @py_assert5 = None + @py_assert3 = dj.Part + @py_assert5 = issubclass(Subject, @py_assert3) + @py_assert7 = not @py_assert5 + if not @py_assert7: + @py_format8 = 'assert not %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.Part\n})\n}' % {'py0':@pytest_ar._saferepr(issubclass) if 'issubclass' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(issubclass) else 'issubclass', 'py1':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert3 = @py_assert5 = @py_assert7 = None + + +def test_class_help(TTest, TTest2): + @py_assert1 = TTest.definition + @py_assert5 = TTest.__doc__ + @py_assert3 = @py_assert1 in @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.definition\n} in %(py6)s\n{%(py6)s = %(py4)s.__doc__\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(TTest) if 'TTest' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest) else 'TTest', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(TTest) if 'TTest' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest) else 'TTest', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + @py_assert1 = TTest.definition + @py_assert5 = TTest2.__doc__ + @py_assert3 = @py_assert1 in @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.definition\n} in %(py6)s\n{%(py6)s = %(py4)s.__doc__\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(TTest) if 'TTest' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest) else 'TTest', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(TTest2) if 'TTest2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest2) else 'TTest2', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_instance_help(TTest, TTest2): + @py_assert1 = TTest() + @py_assert3 = @py_assert1.definition + @py_assert7 = TTest() + @py_assert9 = @py_assert7.__doc__ + @py_assert5 = @py_assert3 in @py_assert9 + if not @py_assert5: + @py_format11 = @pytest_ar._call_reprcompare(('in', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s()\n}.definition\n} in %(py10)s\n{%(py10)s = %(py8)s\n{%(py8)s = %(py6)s()\n}.__doc__\n}', ), (@py_assert3, @py_assert9)) % {'py0':@pytest_ar._saferepr(TTest) if 'TTest' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest) else 'TTest', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(TTest) if 'TTest' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest) else 'TTest', 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = None + @py_assert1 = TTest2() + @py_assert3 = @py_assert1.definition + @py_assert7 = TTest2() + @py_assert9 = @py_assert7.__doc__ + @py_assert5 = @py_assert3 in @py_assert9 + if not @py_assert5: + @py_format11 = @pytest_ar._call_reprcompare(('in', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s()\n}.definition\n} in %(py10)s\n{%(py10)s = %(py8)s\n{%(py8)s = %(py6)s()\n}.__doc__\n}', ), (@py_assert3, @py_assert9)) % {'py0':@pytest_ar._saferepr(TTest2) if 'TTest2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest2) else 'TTest2', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(TTest2) if 'TTest2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TTest2) else 'TTest2', 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = None + + +def test_describe(Subject, User, Experiment): + """real_definition should match original definition""" + rel = Experiment() + context = locals() + s1 = declare(rel.full_table_name, rel.definition, context) + s2 = declare(rel.full_table_name, rel.describe(), context) + @py_assert1 = s2 == s1 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (s2, s1)) % {'py0':@pytest_ar._saferepr(s2) if 's2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s2) else 's2', 'py2':@pytest_ar._saferepr(s1) if 's1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s1) else 's1'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + + +def test_describe_indexes(Subject, User, IndexRich): + """real_definition should match original definition""" + rel = IndexRich() + context = locals() + s1 = declare(rel.full_table_name, rel.definition, context) + s2 = declare(rel.full_table_name, rel.describe(), context) + if not s2: + @py_format1 = (@pytest_ar._format_assertmsg(s1) + '\n>assert %(py0)s') % {'py0': @pytest_ar._saferepr(s2) if ('s2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s2)) else 's2'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + + +def test_describe_dependencies(ThingC, ThingA, ThingB): + """real_definition should match original definition""" + rel = ThingC() + context = locals() + s1 = declare(rel.full_table_name, rel.definition, context) + s2 = declare(rel.full_table_name, rel.describe(), context) + @py_assert1 = s2 == s1 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (s2, s1)) % {'py0':@pytest_ar._saferepr(s2) if 's2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s2) else 's2', 'py2':@pytest_ar._saferepr(s1) if 's1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s1) else 's1'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + + +@pytest.fixture +def Type(schema): + + @schema + class Type(dj.Lookup): + definition = '\n type : varchar(255)\n ' + contents = zip(('Type1', 'Type2', 'Type3')) + + yield Type + Type.drop() + + +@pytest.fixture +def TypeMaster(schema, Type): + + @schema + class TypeMaster(dj.Manual): + definition = '\n master_id : int\n ' + + class Type(dj.Part): + definition = '\n -> TypeMaster\n -> Type\n ' + + yield TypeMaster + TypeMaster.drop() + + +def test_part(TypeMaster): + pass + + +def test_attributes(Auto, Subject, Experiment, Trial, Ephys): + @py_assert1 = Auto.heading + @py_assert3 = @py_assert1.names + @py_assert6 = [ + 'id', 'name'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.heading\n}.names\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Auto) if 'Auto' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Auto) else 'Auto', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert0 = Auto.heading.attributes['id'] + @py_assert2 = @py_assert0.autoincrement + if not @py_assert2: + @py_format4 = 'assert %(py3)s\n{%(py3)s = %(py1)s.autoincrement\n}' % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert0 = @py_assert2 = None + @py_assert1 = Subject.heading + @py_assert3 = @py_assert1.names + @py_assert6 = [ + 'subject_id','real_id','species','date_of_birth','subject_notes'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.heading\n}.names\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = Subject.primary_key + @py_assert4 = [ + 'subject_id'] + @py_assert3 = @py_assert1 == @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert0 = Subject.heading.attributes['subject_id'] + @py_assert2 = @py_assert0.numeric + if not @py_assert2: + @py_format4 = 'assert %(py3)s\n{%(py3)s = %(py1)s.numeric\n}' % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert0 = @py_assert2 = None + @py_assert0 = Subject.heading.attributes['real_id'] + @py_assert2 = @py_assert0.numeric + @py_assert4 = not @py_assert2 + if not @py_assert4: + @py_format5 = 'assert not %(py3)s\n{%(py3)s = %(py1)s.numeric\n}' % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert0 = @py_assert2 = @py_assert4 = None + @py_assert1 = Experiment.heading + @py_assert3 = @py_assert1.names + @py_assert6 = [ + 'subject_id','experiment_id','experiment_date','username','data_path','notes','entry_time'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.heading\n}.names\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = Experiment.primary_key + @py_assert4 = [ + 'subject_id', 'experiment_id'] + @py_assert3 = @py_assert1 == @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Trial.heading + @py_assert3 = @py_assert1.names + @py_assert6 = [ + 'animal', 'experiment_id', 'trial_id', 'start_time'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.heading\n}.names\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = Trial.primary_key + @py_assert4 = [ + 'animal', 'experiment_id', 'trial_id'] + @py_assert3 = @py_assert1 == @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Ephys.heading + @py_assert3 = @py_assert1.names + @py_assert6 = [ + 'animal','experiment_id','trial_id','sampling_frequency','duration'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.heading\n}.names\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = Ephys.primary_key + @py_assert4 = [ + 'animal', 'experiment_id', 'trial_id'] + @py_assert3 = @py_assert1 == @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Ephys.Channel + @py_assert3 = @py_assert1.heading + @py_assert5 = @py_assert3.names + @py_assert8 = [ + 'animal','experiment_id','trial_id','channel','voltage','current'] + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.Channel\n}.heading\n}.names\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert8 = None + @py_assert1 = Ephys.Channel + @py_assert3 = @py_assert1.primary_key + @py_assert6 = [ + 'animal', 'experiment_id', 'trial_id', 'channel'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.Channel\n}.primary_key\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert0 = Ephys.Channel.heading.attributes['voltage'] + @py_assert2 = @py_assert0.is_blob + if not @py_assert2: + @py_format4 = 'assert %(py3)s\n{%(py3)s = %(py1)s.is_blob\n}' % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert0 = @py_assert2 = None + + +def test_dependencies(Experiment, User, Subject, Trial, Ephys): + @py_assert1 = Experiment.full_table_name + @py_assert5 = User.children + @py_assert7 = False + @py_assert9 = @py_assert5(primary=@py_assert7) + @py_assert3 = @py_assert1 in @py_assert9 + if not @py_assert3: + @py_format11 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py10)s\n{%(py10)s = %(py6)s\n{%(py6)s = %(py4)s.children\n}(primary=%(py8)s)\n}', ), (@py_assert1, @py_assert9)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(User) if 'User' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(User) else 'User', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = None + @py_assert2 = Experiment.parents + @py_assert4 = False + @py_assert6 = @py_assert2(primary=@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + User.full_table_name} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.parents\n}(primary=%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = Experiment.full_table_name + @py_assert5 = User.children + @py_assert7 = False + @py_assert9 = @py_assert5(primary=@py_assert7) + @py_assert3 = @py_assert1 in @py_assert9 + if not @py_assert3: + @py_format11 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py10)s\n{%(py10)s = %(py6)s\n{%(py6)s = %(py4)s.children\n}(primary=%(py8)s)\n}', ), (@py_assert1, @py_assert9)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(User) if 'User' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(User) else 'User', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = None + @py_assert2 = Experiment.parents + @py_assert4 = False + @py_assert6 = @py_assert2(primary=@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + User.full_table_name} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.parents\n}(primary=%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = (s.full_table_name for s in Experiment.parents(primary=False, as_objects=True)) + @py_assert3 = set(@py_assert1) + @py_assert6 = { + User.full_table_name} + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = Experiment.full_table_name + @py_assert5 = Subject.descendants + @py_assert7 = @py_assert5() + @py_assert3 = @py_assert1 in @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.descendants\n}()\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = Experiment.full_table_name + @py_assert4 = {s.full_table_name for s in Subject.descendants(as_objects=True)} + @py_assert3 = @py_assert1 in @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Subject.full_table_name + @py_assert5 = Experiment.ancestors + @py_assert7 = @py_assert5() + @py_assert3 = @py_assert1 in @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.ancestors\n}()\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = Subject.full_table_name + @py_assert4 = {s.full_table_name for s in Experiment.ancestors(as_objects=True)} + @py_assert3 = @py_assert1 in @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Trial.full_table_name + @py_assert5 = Experiment.descendants + @py_assert7 = @py_assert5() + @py_assert3 = @py_assert1 in @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.descendants\n}()\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = Trial.full_table_name + @py_assert4 = {s.full_table_name for s in Experiment.descendants(as_objects=True)} + @py_assert3 = @py_assert1 in @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert1 = Experiment.full_table_name + @py_assert5 = Trial.ancestors + @py_assert7 = @py_assert5() + @py_assert3 = @py_assert1 in @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.ancestors\n}()\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = Experiment.full_table_name + @py_assert4 = {s.full_table_name for s in Trial.ancestors(as_objects=True)} + @py_assert3 = @py_assert1 in @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('in', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.full_table_name\n} in %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(Experiment) if 'Experiment' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Experiment) else 'Experiment', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + @py_assert2 = Trial.children + @py_assert4 = True + @py_assert6 = @py_assert2(primary=@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + Ephys.full_table_name, Trial.Condition.full_table_name} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.children\n}(primary=%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert2 = Trial.parts + @py_assert4 = @py_assert2() + @py_assert6 = set(@py_assert4) + @py_assert9 = { + Trial.Condition.full_table_name} + @py_assert8 = @py_assert6 == @py_assert9 + if not @py_assert8: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py0)s(%(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s.parts\n}()\n})\n} == %(py10)s', ), (@py_assert6, @py_assert9)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Trial) if 'Trial' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Trial) else 'Trial', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert9 = None + @py_assert1 = (s.full_table_name for s in Trial.parts(as_objects=True)) + @py_assert3 = set(@py_assert1) + @py_assert6 = { + Trial.Condition.full_table_name} + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert2 = Ephys.parents + @py_assert4 = True + @py_assert6 = @py_assert2(primary=@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + Trial.full_table_name} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.parents\n}(primary=%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = (s.full_table_name for s in Ephys.parents(primary=True, as_objects=True)) + @py_assert3 = set(@py_assert1) + @py_assert6 = { + Trial.full_table_name} + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert2 = Ephys.children + @py_assert4 = True + @py_assert6 = @py_assert2(primary=@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + Ephys.Channel.full_table_name} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.children\n}(primary=%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = (s.full_table_name for s in Ephys.children(primary=True, as_objects=True)) + @py_assert3 = set(@py_assert1) + @py_assert6 = { + Ephys.Channel.full_table_name} + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert2 = Ephys.Channel + @py_assert4 = @py_assert2.parents + @py_assert6 = True + @py_assert8 = @py_assert4(primary=@py_assert6) + @py_assert10 = set(@py_assert8) + @py_assert13 = { + Ephys.full_table_name} + @py_assert12 = @py_assert10 == @py_assert13 + if not @py_assert12: + @py_format15 = @pytest_ar._call_reprcompare(('==', ), (@py_assert12,), ('%(py11)s\n{%(py11)s = %(py0)s(%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s.Channel\n}.parents\n}(primary=%(py7)s)\n})\n} == %(py14)s', ), (@py_assert10, @py_assert13)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(Ephys) if 'Ephys' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Ephys) else 'Ephys', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py14':@pytest_ar._saferepr(@py_assert13)} + @py_format17 = 'assert %(py16)s' % {'py16': @py_format15} + raise AssertionError(@pytest_ar._format_explanation(@py_format17)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert13 = None + @py_assert1 = (s.full_table_name for s in Ephys.Channel.parents(primary=True, as_objects=True)) + @py_assert3 = set(@py_assert1) + @py_assert6 = { + Ephys.full_table_name} + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + + +@pytest.fixture +def A(schema): + + @schema + class A(dj.Manual): + definition = '\n a: int\n ' + + yield A + A.drop() + + +@pytest.fixture +def B(schema, A): + + @schema + class B(dj.Manual): + definition = '\n -> A\n b: int\n ' + + yield B + B.drop() + + +@pytest.fixture +def Master(schema, B): + + @schema + class Master(dj.Manual): + definition = '\n table_master: int\n ' + + class Part(dj.Part): + definition = '\n -> master\n -> B\n ' + + yield Master + Master.drop() + + +def test_descendants_only_contain_part_table(A, Master): + """issue #927""" + @py_assert1 = A.descendants + @py_assert3 = @py_assert1() + @py_assert6 = [ + '`djtest_test1`.`a`', '`djtest_test1`.`b`', '`djtest_test1`.`master__part`'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.descendants\n}()\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + + +def test_bad_attribute_name(schema): + with pytest.raises(dj.errors.DataJointError): + + @schema + class BadName(dj.Manual): + definition = '\n Bad_name : int\n ' + + BadName.drop() + + +def test_bad_fk_rename(schema, A): + """issue #381""" + with pytest.raises(dj.errors.DataJointError): + + @schema + class B(dj.Manual): + definition = '\n b -> A # invalid, the new syntax is (b) -> A\n ' + + B.drop() + + +def test_primary_nullable_foreign_key(schema, Experiment): + with pytest.raises(dj.errors.DataJointError): + + @schema + class Q(dj.Manual): + definition = '\n -> [nullable] Experiment\n ' + + Q.drop() + + +def test_invalid_foreign_key_option(schema, Experiment, User): + with pytest.raises(dj.errors.DataJointError): + + @schema + class R(dj.Manual): + definition = '\n -> Experiment\n ----\n -> [optional] User\n ' + + R.drop() + + +def test_unsupported_datatype(schema): + with pytest.raises(dj.errors.DataJointError): + + @schema + class Q(dj.Manual): + definition = '\n experiment : int\n ---\n description : never\n ' + + Q.drop() + + +def test_int_datatype(schema): + + @schema + class Owner(dj.Manual): + definition = '\n ownerid : int\n ---\n car_count : integer\n ' + + Owner.drop() + + +def test_unsupported_int_datatype(schema): + with pytest.raises(dj.errors.DataJointError): + + @schema + class Driver(dj.Manual): + definition = '\n driverid : tinyint\n ---\n car_count : tinyinteger\n ' + + Driver.drop() + + +def test_long_table_name(schema): + """ + test issue #205 -- reject table names over 64 characters in length + """ + with pytest.raises(dj.errors.DataJointError): + + @schema + class WhyWouldAnyoneCreateATableNameThisLong(dj.Manual): + definition = '\n master : int\n ' + + class WithSuchALongPartNameThatItCrashesMySQL(dj.Part): + definition = '\n -> (master)\n ' + + dj.VirtualModule(schema.database, schema.database).WhyWouldAnyoneCreateATableNameThisLong.drop() \ No newline at end of file diff --git a/tests/test_dependencies.py b/tests/test_dependencies.py new file mode 100644 index 000000000..61c28bc24 --- /dev/null +++ b/tests/test_dependencies.py @@ -0,0 +1,79 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_dependencies.py +# Compiled at: 2023-02-18 20:13:54 +# Size of source mod 2**32: 2633 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from datajoint.dependencies import unite_master_parts +import pytest +from . import connection_root, connection_test +from schemas.default import schema, ThingA, ThingB, ThingC + +def test_unite_master_parts(): + @py_assert1 = [ + '`s`.`a`','`s`.`a__q`','`s`.`b`','`s`.`c`','`s`.`c__q`','`s`.`b__q`','`s`.`d`','`s`.`a__r`'] + @py_assert3 = unite_master_parts(@py_assert1) + @py_assert6 = [ + '`s`.`a`','`s`.`a__q`','`s`.`a__r`','`s`.`b`','`s`.`b__q`','`s`.`c`','`s`.`c__q`','`s`.`d`'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(unite_master_parts) if 'unite_master_parts' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unite_master_parts) else 'unite_master_parts', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + @py_assert1 = [ + '`lab`.`#equipment`','`cells`.`cell_analysis_method`','`cells`.`cell_analysis_method_task_type`','`cells`.`cell_analysis_method_users`','`cells`.`favorite_selection`','`cells`.`cell_analysis_method__cell_selection_params`','`lab`.`#equipment__config`','`cells`.`cell_analysis_method__field_detect_params`'] + @py_assert3 = unite_master_parts(@py_assert1) + @py_assert6 = [ + '`lab`.`#equipment`','`lab`.`#equipment__config`','`cells`.`cell_analysis_method`','`cells`.`cell_analysis_method__cell_selection_params`','`cells`.`cell_analysis_method__field_detect_params`','`cells`.`cell_analysis_method_task_type`','`cells`.`cell_analysis_method_users`','`cells`.`favorite_selection`'] + @py_assert5 = @py_assert3 == @py_assert6 + if not @py_assert5: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py7)s', ), (@py_assert3, @py_assert6)) % {'py0':@pytest_ar._saferepr(unite_master_parts) if 'unite_master_parts' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(unite_master_parts) else 'unite_master_parts', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert6 = None + + +def test_nullable_dependency(ThingA, ThingB, ThingC): + """test nullable unique foreign key""" + a = ThingA() + b = ThingB() + c = ThingC() + a.insert((dict(a=a) for a in range(7))) + b.insert1(dict(b1=1, b2=1, b3=100)) + b.insert1(dict(b1=1, b2=2, b3=100)) + c.insert1(dict(a=0)) + c.insert1(dict(a=1, b1=33)) + c.insert1(dict(a=2, b2=77)) + c.insert1(dict(a=3, b1=1, b2=1)) + c.insert1(dict(a=4, b1=1, b2=2)) + @py_assert2 = len(c) + @py_assert8 = c.fetch + @py_assert10 = @py_assert8() + @py_assert12 = len(@py_assert10) + @py_assert4 = @py_assert2 == @py_assert12 + @py_assert14 = 5 + @py_assert5 = @py_assert12 == @py_assert14 + if not (@py_assert4 and @py_assert5): + @py_format16 = @pytest_ar._call_reprcompare(('==', '=='), (@py_assert4, @py_assert5), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py13)s\n{%(py13)s = %(py6)s(%(py11)s\n{%(py11)s = %(py9)s\n{%(py9)s = %(py7)s.fetch\n}()\n})\n}', + '%(py13)s\n{%(py13)s = %(py6)s(%(py11)s\n{%(py11)s = %(py9)s\n{%(py9)s = %(py7)s.fetch\n}()\n})\n} == %(py15)s'), (@py_assert2, @py_assert12, @py_assert14)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(c) if 'c' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c) else 'c', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py7':@pytest_ar._saferepr(c) if 'c' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c) else 'c', 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12), 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format18 = 'assert %(py17)s' % {'py17': @py_format16} + raise AssertionError(@pytest_ar._format_explanation(@py_format18)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = None + + +def test_unique_dependency(ThingA, ThingB, ThingC): + """test nullable unique foreign key""" + a = ThingA() + b = ThingB() + c = ThingC() + a.insert((dict(a=a) for a in range(7))) + b.insert1(dict(b1=1, b2=1, b3=100)) + b.insert1(dict(b1=1, b2=2, b3=100)) + c.insert1(dict(a=0, b1=1, b2=1)) + with pytest.raises(dj.errors.DuplicateError): + c.insert1(dict(a=1, b1=1, b2=1)) \ No newline at end of file diff --git a/tests/test_erd.py b/tests/test_erd.py new file mode 100644 index 000000000..87bf344f1 --- /dev/null +++ b/tests/test_erd.py @@ -0,0 +1,285 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_erd.py +# Compiled at: 2023-02-18 21:06:56 +# Size of source mod 2**32: 2358 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from . import connection_root, connection_test +from schemas.simple import schema, A, B, E, D, L, OutfitLaunch + +def test_decorator(schema, A, B, E): + @py_assert3 = dj.Lookup + @py_assert5 = issubclass(A, @py_assert3) + if not @py_assert5: + @py_format7 = 'assert %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.Lookup\n})\n}' % {'py0':@pytest_ar._saferepr(issubclass) if 'issubclass' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(issubclass) else 'issubclass', 'py1':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert3 = @py_assert5 = None + @py_assert3 = dj.Part + @py_assert5 = issubclass(A, @py_assert3) + @py_assert7 = not @py_assert5 + if not @py_assert7: + @py_format8 = 'assert not %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.Part\n})\n}' % {'py0':@pytest_ar._saferepr(issubclass) if 'issubclass' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(issubclass) else 'issubclass', 'py1':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = B.database + @py_assert5 = schema.database + @py_assert3 = @py_assert1 == @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.database\n} == %(py6)s\n{%(py6)s = %(py4)s.database\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + @py_assert2 = B.C + @py_assert5 = dj.Part + @py_assert7 = issubclass(@py_assert2, @py_assert5) + if not @py_assert7: + @py_format9 = 'assert %(py8)s\n{%(py8)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s.C\n}, %(py6)s\n{%(py6)s = %(py4)s.Part\n})\n}' % {'py0':@pytest_ar._saferepr(issubclass) if 'issubclass' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(issubclass) else 'issubclass', 'py1':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert5 = @py_assert7 = None + @py_assert1 = B.C + @py_assert3 = @py_assert1.database + @py_assert7 = schema.database + @py_assert5 = @py_assert3 == @py_assert7 + if not @py_assert5: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.C\n}.database\n} == %(py8)s\n{%(py8)s = %(py6)s.database\n}', ), (@py_assert3, @py_assert7)) % {'py0':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = [] + @py_assert3 = B.C + @py_assert5 = @py_assert3.master + @py_assert7 = @py_assert5 is B + @py_assert0 = @py_assert7 + if @py_assert7: + @py_assert13 = E.F + @py_assert15 = @py_assert13.master + @py_assert17 = @py_assert15 is E + @py_assert0 = @py_assert17 + if not @py_assert0: + @py_format9 = @pytest_ar._call_reprcompare(('is', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py2)s.C\n}.master\n} is %(py8)s', ), (@py_assert5, B)) % {'py2':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(B) if 'B' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(B) else 'B'} + @py_format11 = '%(py10)s' % {'py10': @py_format9} + @py_assert1.append(@py_format11) + if @py_assert7: + @py_format19 = @pytest_ar._call_reprcompare(('is', ), (@py_assert17,), ('%(py16)s\n{%(py16)s = %(py14)s\n{%(py14)s = %(py12)s.F\n}.master\n} is %(py18)s', ), (@py_assert15, E)) % {'py12':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E', 'py14':@pytest_ar._saferepr(@py_assert13), 'py16':@pytest_ar._saferepr(@py_assert15), 'py18':@pytest_ar._saferepr(E) if 'E' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(E) else 'E'} + @py_format21 = '%(py20)s' % {'py20': @py_format19} + @py_assert1.append(@py_format21) + @py_format22 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format24 = 'assert %(py23)s' % {'py23': @py_format22} + raise AssertionError(@pytest_ar._format_explanation(@py_format24)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert13 = @py_assert15 = @py_assert17 = None + + +def test_dependencies(schema, A, B, D, E, L): + deps = schema.connection.dependencies + deps.load() + @py_assert1 = (cls.full_table_name in deps for cls in (A, B, B.C, D, E, E.F, L)) + @py_assert3 = all(@py_assert1) + if not @py_assert3: + @py_format5 = 'assert %(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n}' % {'py0':@pytest_ar._saferepr(all) if 'all' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(all) else 'all', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = @py_assert3 = None + @py_assert2 = A() + @py_assert4 = @py_assert2.children + @py_assert6 = @py_assert4() + @py_assert8 = set(@py_assert6) + @py_assert12 = [ + B.full_table_name, D.full_table_name] + @py_assert14 = set(@py_assert12) + @py_assert10 = @py_assert8 == @py_assert14 + if not @py_assert10: + @py_format16 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s()\n}.children\n}()\n})\n} == %(py15)s\n{%(py15)s = %(py11)s(%(py13)s)\n}', ), (@py_assert8, @py_assert14)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(A) if 'A' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(A) else 'A', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py13':@pytest_ar._saferepr(@py_assert12), 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format18 = 'assert %(py17)s' % {'py17': @py_format16} + raise AssertionError(@pytest_ar._format_explanation(@py_format18)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = None + @py_assert2 = D() + @py_assert4 = @py_assert2.parents + @py_assert6 = True + @py_assert8 = @py_assert4(primary=@py_assert6) + @py_assert10 = set(@py_assert8) + @py_assert14 = [ + A.full_table_name] + @py_assert16 = set(@py_assert14) + @py_assert12 = @py_assert10 == @py_assert16 + if not @py_assert12: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert12,), ('%(py11)s\n{%(py11)s = %(py0)s(%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s()\n}.parents\n}(primary=%(py7)s)\n})\n} == %(py17)s\n{%(py17)s = %(py13)s(%(py15)s)\n}', ), (@py_assert10, @py_assert16)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py15':@pytest_ar._saferepr(@py_assert14), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = @py_assert16 = None + @py_assert2 = D() + @py_assert4 = @py_assert2.parents + @py_assert6 = False + @py_assert8 = @py_assert4(primary=@py_assert6) + @py_assert10 = set(@py_assert8) + @py_assert14 = [ + L.full_table_name] + @py_assert16 = set(@py_assert14) + @py_assert12 = @py_assert10 == @py_assert16 + if not @py_assert12: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert12,), ('%(py11)s\n{%(py11)s = %(py0)s(%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s()\n}.parents\n}(primary=%(py7)s)\n})\n} == %(py17)s\n{%(py17)s = %(py13)s(%(py15)s)\n}', ), (@py_assert10, @py_assert16)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(D) if 'D' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(D) else 'D', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py15':@pytest_ar._saferepr(@py_assert14), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = @py_assert16 = None + @py_assert2 = deps.descendants + @py_assert5 = L.full_table_name + @py_assert7 = @py_assert2(@py_assert5) + @py_assert9 = set(@py_assert7) + @py_assert11 = @py_assert9.issubset + @py_assert13 = (cls.full_table_name for cls in (L, D, E, E.F)) + @py_assert15 = @py_assert11(@py_assert13) + if not @py_assert15: + @py_format17 = 'assert %(py16)s\n{%(py16)s = %(py12)s\n{%(py12)s = %(py10)s\n{%(py10)s = %(py0)s(%(py8)s\n{%(py8)s = %(py3)s\n{%(py3)s = %(py1)s.descendants\n}(%(py6)s\n{%(py6)s = %(py4)s.full_table_name\n})\n})\n}.issubset\n}(%(py14)s)\n}' % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(deps) if 'deps' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(deps) else 'deps', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(L) if 'L' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(L) else 'L', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py16':@pytest_ar._saferepr(@py_assert15)} + raise AssertionError(@pytest_ar._format_explanation(@py_format17)) + @py_assert2 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = @py_assert13 = @py_assert15 = None + + +def test_erd(schema, A, B, D, E, L): + @py_assert1 = dj.diagram + @py_assert3 = @py_assert1.diagram_active + if not @py_assert3: + @py_format5 = (@pytest_ar._format_assertmsg('Failed to import networkx and pydot') + '\n>assert %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.diagram\n}.diagram_active\n}') % {'py0':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = @py_assert3 = None + erd = dj.ERD(schema, context=(locals())) + graph = erd._make_graph() + @py_assert1 = (cls.__name__ for cls in (A, B, D, E, L)) + @py_assert3 = set(@py_assert1) + @py_assert5 = @py_assert3.issubset + @py_assert8 = graph.nodes + @py_assert10 = @py_assert8() + @py_assert12 = @py_assert5(@py_assert10) + if not @py_assert12: + @py_format14 = 'assert %(py13)s\n{%(py13)s = %(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n}.issubset\n}(%(py11)s\n{%(py11)s = %(py9)s\n{%(py9)s = %(py7)s.nodes\n}()\n})\n}' % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py7':@pytest_ar._saferepr(graph) if 'graph' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(graph) else 'graph', 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12)} + raise AssertionError(@pytest_ar._format_explanation(@py_format14)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert8 = @py_assert10 = @py_assert12 = None + + +def test_erd_algebra(A, B, D, E, L): + erd0 = dj.ERD(B) + erd1 = erd0 + 3 + erd2 = dj.Di(E) - 3 + erd3 = erd1 * erd2 + erd4 = (erd0 + E).add_parts() - B - E + @py_assert1 = erd0.nodes_to_show + @py_assert5 = (cls.full_table_name for cls in [B]) + @py_assert7 = set(@py_assert5) + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.nodes_to_show\n} == %(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(erd0) if 'erd0' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(erd0) else 'erd0', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = erd1.nodes_to_show + @py_assert5 = (cls.full_table_name for cls in (B, B.C, E, E.F)) + @py_assert7 = set(@py_assert5) + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.nodes_to_show\n} == %(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(erd1) if 'erd1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(erd1) else 'erd1', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = erd2.nodes_to_show + @py_assert5 = (cls.full_table_name for cls in (A, B, D, E, L)) + @py_assert7 = set(@py_assert5) + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.nodes_to_show\n} == %(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(erd2) if 'erd2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(erd2) else 'erd2', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = erd3.nodes_to_show + @py_assert5 = (cls.full_table_name for cls in (B, E)) + @py_assert7 = set(@py_assert5) + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.nodes_to_show\n} == %(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(erd3) if 'erd3' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(erd3) else 'erd3', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + @py_assert1 = erd4.nodes_to_show + @py_assert5 = (cls.full_table_name for cls in (B.C, E.F)) + @py_assert7 = set(@py_assert5) + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.nodes_to_show\n} == %(py8)s\n{%(py8)s = %(py4)s(%(py6)s)\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(erd4) if 'erd4' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(erd4) else 'erd4', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + + +def test_repr_svg(schema): + erd = dj.ERD(schema, context=(locals())) + svg = erd._repr_svg_() + @py_assert1 = [] + @py_assert3 = svg.startswith + @py_assert5 = 'assert %(py8)s') % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + @py_assert1 = schema.external['local'] + @py_assert4 = listOfErrors[0][0] + @py_assert6 = dict(hash=@py_assert4) + @py_assert8 = @py_assert1 & @py_assert6 + @py_assert9 = len(@py_assert8) + @py_assert12 = 1 + @py_assert11 = @py_assert9 == @py_assert12 + if not @py_assert11: + @py_format14 = @pytest_ar._call_reprcompare(('==', ), (@py_assert11,), ('%(py10)s\n{%(py10)s = %(py0)s((%(py2)s & %(py7)s\n{%(py7)s = %(py3)s(hash=%(py5)s)\n}))\n} == %(py13)s', ), (@py_assert9, @py_assert12)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(dict) if 'dict' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dict) else 'dict', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py10':@pytest_ar._saferepr(@py_assert9), 'py13':@pytest_ar._saferepr(@py_assert12)} + @py_format16 = (@pytest_ar._format_assertmsg('unexpected number of rows in external table') + '\n>assert %(py15)s') % {'py15': @py_format14} + raise AssertionError(@pytest_ar._format_explanation(@py_format16)) + @py_assert1 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert9 = @py_assert11 = @py_assert12 = None + os.chmod(path1, currentMode) \ No newline at end of file diff --git a/tests/test_external_class.py b/tests/test_external_class.py new file mode 100644 index 000000000..176c1be5d --- /dev/null +++ b/tests/test_external_class.py @@ -0,0 +1,123 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_external_class.py +# Compiled at: 2023-02-18 21:36:07 +# Size of source mod 2**32: 1617 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj, numpy as np +from numpy.testing import assert_almost_equal +from . import connection_root, connection_test, bucket +from schemas.external import schema, stores, store_local, store_share, Simple, Image, Dimension, Seed + +def test_heading(Simple): + heading = Simple().heading + @py_assert0 = 'item' + @py_assert2 = @py_assert0 in heading + if not @py_assert2: + @py_format4 = @pytest_ar._call_reprcompare(('in', ), (@py_assert2,), ('%(py1)s in %(py3)s', ), (@py_assert0, heading)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(heading) if 'heading' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(heading) else 'heading'} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert0 = @py_assert2 = None + @py_assert0 = heading['item'] + @py_assert2 = @py_assert0.is_external + if not @py_assert2: + @py_format4 = 'assert %(py3)s\n{%(py3)s = %(py1)s.is_external\n}' % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert0 = @py_assert2 = None + + +def test_insert_and_fetch(Simple): + original_list = [ + 1, 3, 8] + Simple().insert1(dict(simple=1, item=original_list)) + q = (Simple() & {'simple': 1}).fetch('item')[0] + @py_assert2 = list(q) + @py_assert4 = @py_assert2 == original_list + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, original_list)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py1':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(original_list) if 'original_list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_list) else 'original_list'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + q = (Simple() & {'simple': 1}).fetch1('item') + @py_assert2 = list(q) + @py_assert4 = @py_assert2 == original_list + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, original_list)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py1':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(original_list) if 'original_list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_list) else 'original_list'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + q = (Simple() & {'simple': 1}).fetch1() + @py_assert1 = q['item'] + @py_assert3 = list(@py_assert1) + @py_assert5 = @py_assert3 == original_list + if not @py_assert5: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py6)s', ), (@py_assert3, original_list)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(original_list) if 'original_list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_list) else 'original_list'} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + previous_cache = dj.config['cache'] + dj.config['cache'] = None + q = (Simple() & {'simple': 1}).fetch1() + @py_assert1 = q['item'] + @py_assert3 = list(@py_assert1) + @py_assert5 = @py_assert3 == original_list + if not @py_assert5: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py6)s', ), (@py_assert3, original_list)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(original_list) if 'original_list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_list) else 'original_list'} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + dj.config['cache'] = previous_cache + q = (Simple() & {'simple': 1}).fetch1() + @py_assert1 = q['item'] + @py_assert3 = list(@py_assert1) + @py_assert5 = @py_assert3 == original_list + if not @py_assert5: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py6)s', ), (@py_assert3, original_list)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(original_list) if 'original_list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_list) else 'original_list'} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_populate(Image, Dimension, Seed): + np.random.seed(500) + image = Image() + image.populate() + remaining, total = image.progress() + @py_assert1 = [] + @py_assert6 = Dimension() + @py_assert9 = Seed() + @py_assert11 = @py_assert6 * @py_assert9 + @py_assert12 = len(@py_assert11) + @py_assert3 = total == @py_assert12 + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert19 = 0 + @py_assert18 = remaining == @py_assert19 + @py_assert0 = @py_assert18 + if not @py_assert0: + @py_format14 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py13)s\n{%(py13)s = %(py4)s((%(py7)s\n{%(py7)s = %(py5)s()\n} * %(py10)s\n{%(py10)s = %(py8)s()\n}))\n}', ), (total, @py_assert12)) % {'py2':@pytest_ar._saferepr(total) if 'total' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(total) else 'total', 'py4':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py5':@pytest_ar._saferepr(Dimension) if 'Dimension' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Dimension) else 'Dimension', 'py7':@pytest_ar._saferepr(@py_assert6), 'py8':@pytest_ar._saferepr(Seed) if 'Seed' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Seed) else 'Seed', 'py10':@pytest_ar._saferepr(@py_assert9), 'py13':@pytest_ar._saferepr(@py_assert12)} + @py_format16 = '%(py15)s' % {'py15': @py_format14} + @py_assert1.append(@py_format16) + if @py_assert3: + @py_format21 = @pytest_ar._call_reprcompare(('==', ), (@py_assert18,), ('%(py17)s == %(py20)s', ), (remaining, @py_assert19)) % {'py17':@pytest_ar._saferepr(remaining) if 'remaining' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(remaining) else 'remaining', 'py20':@pytest_ar._saferepr(@py_assert19)} + @py_format23 = '%(py22)s' % {'py22': @py_format21} + @py_assert1.append(@py_format23) + @py_format24 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format26 = 'assert %(py25)s' % {'py25': @py_format24} + raise AssertionError(@pytest_ar._format_explanation(@py_format26)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert6 = @py_assert9 = @py_assert11 = @py_assert12 = @py_assert18 = @py_assert19 = None + for img, neg, dimensions in zip(*(image * Dimension()).fetch('img', 'neg', 'dimensions')): + @py_assert2 = img.shape + @py_assert4 = list(@py_assert2) + @py_assert9 = list(dimensions) + @py_assert6 = @py_assert4 == @py_assert9 + if not @py_assert6: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert6,), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s.shape\n})\n} == %(py10)s\n{%(py10)s = %(py7)s(%(py8)s)\n}', ), (@py_assert4, @py_assert9)) % {'py0':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py1':@pytest_ar._saferepr(img) if 'img' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(img) else 'img', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(list) if 'list' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(list) else 'list', 'py8':@pytest_ar._saferepr(dimensions) if 'dimensions' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dimensions) else 'dimensions', 'py10':@pytest_ar._saferepr(@py_assert9)} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + else: + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert9 = None + assert_almost_equal(img, -neg) \ No newline at end of file diff --git a/tests/test_fetch.py b/tests/test_fetch.py new file mode 100644 index 000000000..9fb4745ff --- /dev/null +++ b/tests/test_fetch.py @@ -0,0 +1,694 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_fetch.py +# Compiled at: 2023-02-19 07:56:50 +# Size of source mod 2**32: 13190 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj, numpy as np +from operator import itemgetter +import pandas, itertools, decimal, logging, io, os, pytest +from . import connection_root, connection_test +from schemas.default import schema, Subject, Language, User, DecimalPrimaryKey, NullableNumbers, Child, Parent, TTest3, Stimulus +logger = logging.getLogger('datajoint') + +def test_getattribute(Subject): + """Testing Fetch.__call__ with attributes""" + list1 = sorted(Subject.proj().fetch(as_dict=True), key=(itemgetter('subject_id'))) + list2 = sorted((Subject.fetch(dj.key)), key=(itemgetter('subject_id'))) + for l1, l2 in zip(list1, list2): + @py_assert1 = l1 == l2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (l1, l2)) % {'py0':@pytest_ar._saferepr(l1) if 'l1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l1) else 'l1', 'py2':@pytest_ar._saferepr(l2) if 'l2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l2) else 'l2'} + @py_format5 = (@pytest_ar._format_assertmsg('Primary key is not returned correctly') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert1 = None + + tmp = Subject.fetch(order_by='subject_id') + subject_notes, key, real_id = Subject.fetch('subject_notes', dj.key, 'real_id') + np.testing.assert_array_equal(sorted(subject_notes), sorted(tmp['subject_notes'])) + np.testing.assert_array_equal(sorted(real_id), sorted(tmp['real_id'])) + list1 = sorted(key, key=(itemgetter('subject_id'))) + for l1, l2 in zip(list1, list2): + @py_assert1 = l1 == l2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (l1, l2)) % {'py0':@pytest_ar._saferepr(l1) if 'l1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l1) else 'l1', 'py2':@pytest_ar._saferepr(l2) if 'l2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l2) else 'l2'} + @py_format5 = (@pytest_ar._format_assertmsg('Primary key is not returned correctly') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert1 = None + + +def test_getattribute_for_fetch1(Subject): + """Testing Fetch1.__call__ with attributes""" + @py_assert1 = 'subject_id=10' + @py_assert3 = Subject & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'subject_id' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 10 + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = 'subject_id=10' + @py_assert3 = Subject & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'subject_id' + @py_assert8 = 'species' + @py_assert10 = @py_assert4(@py_assert6, @py_assert8) + @py_assert13 = (10, 'monkey') + @py_assert12 = @py_assert10 == @py_assert13 + if not @py_assert12: + @py_format15 = @pytest_ar._call_reprcompare(('==', ), (@py_assert12,), ('%(py11)s\n{%(py11)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s, %(py9)s)\n} == %(py14)s', ), (@py_assert10, @py_assert13)) % {'py0':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py14':@pytest_ar._saferepr(@py_assert13)} + @py_format17 = 'assert %(py16)s' % {'py16': @py_format15} + raise AssertionError(@pytest_ar._format_explanation(@py_format17)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert13 = None + + +def test_order_by(Language): + """Tests order_by sorting order""" + languages = Language.contents + for ord_name, ord_lang in (itertools.product)(*2 * [['ASC', 'DESC']]): + cur = Language.fetch(order_by=('name ' + ord_name, 'language ' + ord_lang)) + languages.sort(key=(itemgetter(1)), reverse=(ord_lang == 'DESC')) + languages.sort(key=(itemgetter(0)), reverse=(ord_name == 'DESC')) + for c, l in zip(cur, languages): + @py_assert1 = np.all + @py_assert3 = (cc == ll for cc, ll in zip(c, l)) + @py_assert5 = @py_assert1(@py_assert3) + if not @py_assert5: + @py_format7 = (@pytest_ar._format_assertmsg('Sorting order is different') + '\n>assert %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.all\n}(%(py4)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + else: + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_order_by_default(Language): + """Tests order_by sorting order with defaults""" + languages = Language.contents + cur = Language.fetch(order_by=('language', 'name DESC')) + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + for c, l in zip(cur, languages): + @py_assert1 = np.all + @py_assert3 = [cc == ll for cc, ll in zip(c, l)] + @py_assert5 = @py_assert1(@py_assert3) + if not @py_assert5: + @py_format7 = (@pytest_ar._format_assertmsg('Sorting order is different') + '\n>assert %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.all\n}(%(py4)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + else: + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_limit(Language): + """Test the limit kwarg""" + limit = 4 + cur = Language.fetch(limit=limit) + @py_assert2 = len(cur) + @py_assert4 = @py_assert2 == limit + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, limit)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(cur) if 'cur' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(cur) else 'cur', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(limit) if 'limit' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(limit) else 'limit'} + @py_format8 = (@pytest_ar._format_assertmsg('Length is not correct') + '\n>assert %(py7)s') % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + + +def test_order_by_limit(Language): + """Test the combination of order by and limit kwargs""" + languages = Language.contents + cur = Language.fetch(limit=4, order_by=['language', 'name DESC']) + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + @py_assert2 = len(cur) + @py_assert5 = 4 + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(cur) if 'cur' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(cur) else 'cur', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = (@pytest_ar._format_assertmsg('Length is not correct') + '\n>assert %(py8)s') % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + for c, l in list(zip(cur, languages))[:4]: + @py_assert1 = np.all + @py_assert3 = [cc == ll for cc, ll in zip(c, l)] + @py_assert5 = @py_assert1(@py_assert3) + if not @py_assert5: + @py_format7 = (@pytest_ar._format_assertmsg('Sorting order is different') + '\n>assert %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.all\n}(%(py4)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + else: + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_head_tail(Language, User): + query = User * Language + n = 5 + frame = query.head(n, format='frame') + @py_assert3 = pandas.DataFrame + @py_assert5 = isinstance(frame, @py_assert3) + if not @py_assert5: + @py_format7 = 'assert %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.DataFrame\n})\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py1':@pytest_ar._saferepr(frame) if 'frame' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(frame) else 'frame', 'py2':@pytest_ar._saferepr(pandas) if 'pandas' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pandas) else 'pandas', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert3 = @py_assert5 = None + array = query.head(n, format='array') + @py_assert1 = array.size + @py_assert3 = @py_assert1 == n + if not @py_assert3: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.size\n} == %(py4)s', ), (@py_assert1, n)) % {'py0':@pytest_ar._saferepr(array) if 'array' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(array) else 'array', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert1 = @py_assert3 = None + @py_assert2 = len(frame) + @py_assert4 = @py_assert2 == n + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, n)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(frame) if 'frame' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(frame) else 'frame', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + @py_assert1 = query.primary_key + @py_assert5 = frame.index + @py_assert7 = @py_assert5.names + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.index\n}.names\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(query) if 'query' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(query) else 'query', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(frame) if 'frame' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(frame) else 'frame', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + n = 4 + frame = query.tail(n, format='frame') + array = query.tail(n, format='array') + @py_assert1 = array.size + @py_assert3 = @py_assert1 == n + if not @py_assert3: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.size\n} == %(py4)s', ), (@py_assert1, n)) % {'py0':@pytest_ar._saferepr(array) if 'array' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(array) else 'array', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert1 = @py_assert3 = None + @py_assert2 = len(frame) + @py_assert4 = @py_assert2 == n + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, n)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(frame) if 'frame' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(frame) else 'frame', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + @py_assert1 = query.primary_key + @py_assert5 = frame.index + @py_assert7 = @py_assert5.names + @py_assert3 = @py_assert1 == @py_assert7 + if not @py_assert3: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.primary_key\n} == %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py4)s.index\n}.names\n}', ), (@py_assert1, @py_assert7)) % {'py0':@pytest_ar._saferepr(query) if 'query' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(query) else 'query', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(frame) if 'frame' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(frame) else 'frame', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + + +def test_limit_offset(Language): + """Test the limit and offset kwargs together""" + languages = Language.contents + cur = Language.fetch(offset=2, limit=4, order_by=['language', 'name DESC']) + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + @py_assert2 = len(cur) + @py_assert5 = 4 + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(cur) if 'cur' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(cur) else 'cur', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = (@pytest_ar._format_assertmsg('Length is not correct') + '\n>assert %(py8)s') % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + for c, l in list(zip(cur, languages[2:6])): + @py_assert1 = np.all + @py_assert3 = [cc == ll for cc, ll in zip(c, l)] + @py_assert5 = @py_assert1(@py_assert3) + if not @py_assert5: + @py_format7 = (@pytest_ar._format_assertmsg('Sorting order is different') + '\n>assert %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.all\n}(%(py4)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + else: + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_iter(Language): + """Test iterator""" + languages = Language.contents + cur = Language.fetch(order_by=['language', 'name DESC']) + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + for (name, lang), (tname, tlang) in list(zip(cur, languages)): + @py_assert1 = [] + @py_assert3 = name == tname + @py_assert0 = @py_assert3 + if @py_assert3: + @py_assert9 = lang == tlang + @py_assert0 = @py_assert9 + else: + if not @py_assert0: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s == %(py4)s', ), (name, tname)) % {'py2':@pytest_ar._saferepr(name) if 'name' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(name) else 'name', 'py4':@pytest_ar._saferepr(tname) if 'tname' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tname) else 'tname'} + @py_format7 = '%(py6)s' % {'py6': @py_format5} + @py_assert1.append(@py_format7) + if @py_assert3: + @py_format11 = @pytest_ar._call_reprcompare(('==', ), (@py_assert9,), ('%(py8)s == %(py10)s', ), (lang, tlang)) % {'py8':@pytest_ar._saferepr(lang) if 'lang' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(lang) else 'lang', 'py10':@pytest_ar._saferepr(tlang) if 'tlang' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tlang) else 'tlang'} + @py_format13 = '%(py12)s' % {'py12': @py_format11} + @py_assert1.append(@py_format13) + @py_format14 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format16 = (@pytest_ar._format_assertmsg('Values are not the same') + '\n>assert %(py15)s') % {'py15': @py_format14} + raise AssertionError(@pytest_ar._format_explanation(@py_format16)) + @py_assert0 = @py_assert1 = @py_assert3 = @py_assert9 = None + + cur = Language.fetch(as_dict=True, order_by=('language', 'name DESC')) + for row, (tname, tlang) in list(zip(cur, languages)): + @py_assert1 = [] + @py_assert2 = row['name'] + @py_assert4 = @py_assert2 == tname + @py_assert0 = @py_assert4 + if @py_assert4: + @py_assert9 = row['language'] + @py_assert11 = @py_assert9 == tlang + @py_assert0 = @py_assert11 + else: + if not @py_assert0: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s == %(py5)s', ), (@py_assert2, tname)) % {'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(tname) if 'tname' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tname) else 'tname'} + @py_format8 = '%(py7)s' % {'py7': @py_format6} + @py_assert1.append(@py_format8) + if @py_assert4: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert11,), ('%(py10)s == %(py12)s', ), (@py_assert9, tlang)) % {'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(tlang) if 'tlang' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tlang) else 'tlang'} + @py_format15 = '%(py14)s' % {'py14': @py_format13} + @py_assert1.append(@py_format15) + @py_format16 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format18 = (@pytest_ar._format_assertmsg('Values are not the same') + '\n>assert %(py17)s') % {'py17': @py_format16} + raise AssertionError(@pytest_ar._format_explanation(@py_format18)) + @py_assert0 = @py_assert1 = @py_assert2 = @py_assert4 = @py_assert9 = @py_assert11 = None + + +def test_keys(Language): + """test key fetch""" + languages = Language.contents + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + cur = Language.fetch('name', 'language', order_by=('language', 'name DESC')) + cur2 = list(Language.fetch('KEY', order_by=['language', 'name DESC'])) + for c, c2 in zip(zip(*cur), cur2): + @py_assert4 = c2.values + @py_assert6 = @py_assert4() + @py_assert8 = tuple(@py_assert6) + @py_assert1 = c == @py_assert8 + if not @py_assert1: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py9)s\n{%(py9)s = %(py2)s(%(py7)s\n{%(py7)s = %(py5)s\n{%(py5)s = %(py3)s.values\n}()\n})\n}', ), (c, @py_assert8)) % {'py0':@pytest_ar._saferepr(c) if 'c' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c) else 'c', 'py2':@pytest_ar._saferepr(tuple) if 'tuple' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tuple) else 'tuple', 'py3':@pytest_ar._saferepr(c2) if 'c2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c2) else 'c2', 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = (@pytest_ar._format_assertmsg('Values are not the same') + '\n>assert %(py11)s') % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + else: + @py_assert1 = @py_assert4 = @py_assert6 = @py_assert8 = None + + +def test_attributes_as_dict(Subject): + attrs = ('species', 'date_of_birth') + result = (Subject.fetch)(*attrs, **{'as_dict': True}) + @py_assert1 = [] + @py_assert4 = bool(result) + @py_assert0 = @py_assert4 + if @py_assert4: + @py_assert9 = len(result) + @py_assert14 = Subject() + @py_assert16 = len(@py_assert14) + @py_assert11 = @py_assert9 == @py_assert16 + @py_assert0 = @py_assert11 + if not @py_assert0: + @py_format6 = '%(py5)s\n{%(py5)s = %(py2)s(%(py3)s)\n}' % {'py2':@pytest_ar._saferepr(bool) if 'bool' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(bool) else 'bool', 'py3':@pytest_ar._saferepr(result) if 'result' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(result) else 'result', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_assert1.append(@py_format6) + if @py_assert4: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert11,), ('%(py10)s\n{%(py10)s = %(py7)s(%(py8)s)\n} == %(py17)s\n{%(py17)s = %(py12)s(%(py15)s\n{%(py15)s = %(py13)s()\n})\n}', ), (@py_assert9, @py_assert16)) % {'py7':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py8':@pytest_ar._saferepr(result) if 'result' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(result) else 'result', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py13':@pytest_ar._saferepr(Subject) if 'Subject' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Subject) else 'Subject', 'py15':@pytest_ar._saferepr(@py_assert14), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = '%(py19)s' % {'py19': @py_format18} + @py_assert1.append(@py_format20) + @py_format21 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format23 = 'assert %(py22)s' % {'py22': @py_format21} + raise AssertionError(@pytest_ar._format_explanation(@py_format23)) + @py_assert0 = @py_assert1 = @py_assert4 = @py_assert9 = @py_assert11 = @py_assert14 = @py_assert16 = None + @py_assert1 = result[0] + @py_assert3 = set(@py_assert1) + @py_assert8 = set(attrs) + @py_assert5 = @py_assert3 == @py_assert8 + if not @py_assert5: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n} == %(py9)s\n{%(py9)s = %(py6)s(%(py7)s)\n}', ), (@py_assert3, @py_assert8)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py7':@pytest_ar._saferepr(attrs) if 'attrs' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(attrs) else 'attrs', 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert8 = None + + +def test_fetch1_step1(Language): + key = {'name':'Edgar', + 'language':'Japanese'} + true = Language.contents[-1] + dat = (Language & key).fetch1() + for k, (ke, c) in zip(true, dat.items()): + @py_assert1 = k == c + @py_assert6 = Language & key + @py_assert7 = @py_assert6.fetch1 + @py_assert10 = @py_assert7(ke) + @py_assert2 = c == @py_assert10 + if not (@py_assert1 and @py_assert2): + @py_format12 = @pytest_ar._call_reprcompare(('==', '=='), (@py_assert1, @py_assert2), ('%(py0)s == %(py3)s', + '%(py3)s == %(py11)s\n{%(py11)s = %(py8)s\n{%(py8)s = (%(py4)s & %(py5)s).fetch1\n}(%(py9)s)\n}'), (k, c, @py_assert10)) % {'py0':@pytest_ar._saferepr(k) if 'k' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(k) else 'k', 'py3':@pytest_ar._saferepr(c) if 'c' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c) else 'c', 'py4':@pytest_ar._saferepr(Language) if 'Language' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Language) else 'Language', 'py5':@pytest_ar._saferepr(key) if 'key' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key) else 'key', 'py8':@pytest_ar._saferepr(@py_assert7), 'py9':@pytest_ar._saferepr(ke) if 'ke' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ke) else 'ke', 'py11':@pytest_ar._saferepr(@py_assert10)} + @py_format14 = (@pytest_ar._format_assertmsg('Values are not the same') + '\n>assert %(py13)s') % {'py13': @py_format12} + raise AssertionError(@pytest_ar._format_explanation(@py_format14)) + else: + @py_assert1 = @py_assert2 = @py_assert6 = @py_assert7 = @py_assert10 = None + + +def test_misspelled_attribute(Language): + with pytest.raises(dj.DataJointError): + f = (Language & 'lang = "ENGLISH"').fetch() + + +def test_repr(Subject): + """Test string representation of fetch, returning table preview""" + repr = Subject.fetch.__repr__() + n = len(repr.strip().split('\n')) + limit = dj.config['display.limit'] + @py_assert1 = 3 + @py_assert3 = n - @py_assert1 + @py_assert4 = @py_assert3 <= limit + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('<=', ), (@py_assert4,), ('(%(py0)s - %(py2)s) <= %(py5)s', ), (@py_assert3, limit)) % {'py0':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(limit) if 'limit' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(limit) else 'limit'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + + +def test_fetch_none(Language): + """Test preparing attributes for getitem""" + with pytest.raises(dj.DataJointError): + Language.fetch(None) + + +def test_asdict(Language): + """Test returns as dictionaries""" + d = Language.fetch(as_dict=True) + for dd in d: + @py_assert3 = isinstance(dd, dict) + if not @py_assert3: + @py_format5 = 'assert %(py4)s\n{%(py4)s = %(py0)s(%(py1)s, %(py2)s)\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py1':@pytest_ar._saferepr(dd) if 'dd' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dd) else 'dd', 'py2':@pytest_ar._saferepr(dict) if 'dict' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dict) else 'dict', 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert3 = None + + +def test_offset(Language): + """Tests offset""" + cur = Language.fetch(limit=4, offset=1, order_by=['language', 'name DESC']) + languages = Language.contents + languages.sort(key=(itemgetter(0)), reverse=True) + languages.sort(key=(itemgetter(1)), reverse=False) + @py_assert2 = len(cur) + @py_assert5 = 4 + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(cur) if 'cur' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(cur) else 'cur', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = (@pytest_ar._format_assertmsg('Length is not correct') + '\n>assert %(py8)s') % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + for c, l in list(zip(cur, languages[1:]))[:4]: + @py_assert1 = np.all + @py_assert3 = [cc == ll for cc, ll in zip(c, l)] + @py_assert5 = @py_assert1(@py_assert3) + if not @py_assert5: + @py_format7 = (@pytest_ar._format_assertmsg('Sorting order is different') + '\n>assert %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.all\n}(%(py4)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + else: + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_limit_warning(Language): + """Tests whether warning is raised if offset is used without limit.""" + log_capture = io.StringIO() + stream_handler = logging.StreamHandler(log_capture) + log_format = logging.Formatter('[%(asctime)s][%(funcName)s][%(levelname)s]: %(message)s') + stream_handler.setFormatter(log_format) + stream_handler.set_name('test_limit_warning') + logger.addHandler(stream_handler) + Language.fetch(offset=1) + log_contents = log_capture.getvalue() + log_capture.close() + for handler in logger.handlers: + if handler.name == 'test_limit_warning': + logger.removeHandler(handler) + + @py_assert0 = '[WARNING]: Offset set, but no limit.' + @py_assert2 = @py_assert0 in log_contents + if not @py_assert2: + @py_format4 = @pytest_ar._call_reprcompare(('in', ), (@py_assert2,), ('%(py1)s in %(py3)s', ), (@py_assert0, log_contents)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(log_contents) if 'log_contents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(log_contents) else 'log_contents'} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert0 = @py_assert2 = None + + +def test_len(Language): + """Tests __len__""" + @py_assert2 = Language.fetch + @py_assert4 = @py_assert2() + @py_assert6 = len(@py_assert4) + @py_assert11 = Language() + @py_assert13 = len(@py_assert11) + @py_assert8 = @py_assert6 == @py_assert13 + if not @py_assert8: + @py_format15 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py0)s(%(py5)s\n{%(py5)s = %(py3)s\n{%(py3)s = %(py1)s.fetch\n}()\n})\n} == %(py14)s\n{%(py14)s = %(py9)s(%(py12)s\n{%(py12)s = %(py10)s()\n})\n}', ), (@py_assert6, @py_assert13)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(Language) if 'Language' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Language) else 'Language', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py10':@pytest_ar._saferepr(Language) if 'Language' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Language) else 'Language', 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13)} + @py_format17 = (@pytest_ar._format_assertmsg('__len__ is not behaving properly') + '\n>assert %(py16)s') % {'py16': @py_format15} + raise AssertionError(@pytest_ar._format_explanation(@py_format17)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert11 = @py_assert13 = None + + +def test_fetch1_step2(Language): + """Tests whether fetch1 raises error""" + with pytest.raises(dj.DataJointError): + Language.fetch1() + + +def test_fetch1_step3(Language): + """Tests whether fetch1 raises error""" + with pytest.raises(dj.DataJointError): + Language.fetch1('name') + + +def test_decimal(DecimalPrimaryKey): + """Tests that decimal fields are correctly fetched and used in restrictions, see issue #334""" + rel = DecimalPrimaryKey() + rel.insert1([decimal.Decimal('3.1415926')]) + keys = rel.fetch() + @py_assert2 = keys[0] + @py_assert4 = rel & @py_assert2 + @py_assert5 = len(@py_assert4) + @py_assert8 = 1 + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s((%(py1)s & %(py3)s))\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert8 = None + keys = rel.fetch(dj.key) + @py_assert2 = keys[1] + @py_assert4 = rel & @py_assert2 + @py_assert5 = len(@py_assert4) + @py_assert8 = 1 + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s((%(py1)s & %(py3)s))\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(rel) if 'rel' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(rel) else 'rel', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert8 = None + + +def test_nullable_numbers(NullableNumbers): + """test mixture of values and nulls in numeric attributes""" + np.random.seed(800) + table = NullableNumbers() + table.insert(((k, np.random.randn(), np.random.randint(-1000, 1000), np.random.randn()) for k in range(10))) + table.insert1((100, None, None, None)) + f, d, i = table.fetch('fvalue', 'dvalue', 'ivalue') + @py_assert0 = None + @py_assert2 = @py_assert0 in i + if not @py_assert2: + @py_format4 = @pytest_ar._call_reprcompare(('in', ), (@py_assert2,), ('%(py1)s in %(py3)s', ), (@py_assert0, i)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(i) if 'i' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(i) else 'i'} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert0 = @py_assert2 = None + @py_assert2 = np.isnan + @py_assert5 = @py_assert2(d) + @py_assert7 = any(@py_assert5) + if not @py_assert7: + @py_format9 = 'assert %(py8)s\n{%(py8)s = %(py0)s(%(py6)s\n{%(py6)s = %(py3)s\n{%(py3)s = %(py1)s.isnan\n}(%(py4)s)\n})\n}' % {'py0':@pytest_ar._saferepr(any) if 'any' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(any) else 'any', 'py1':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(d) if 'd' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(d) else 'd', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert5 = @py_assert7 = None + @py_assert2 = np.isnan + @py_assert5 = @py_assert2(f) + @py_assert7 = any(@py_assert5) + if not @py_assert7: + @py_format9 = 'assert %(py8)s\n{%(py8)s = %(py0)s(%(py6)s\n{%(py6)s = %(py3)s\n{%(py3)s = %(py1)s.isnan\n}(%(py4)s)\n})\n}' % {'py0':@pytest_ar._saferepr(any) if 'any' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(any) else 'any', 'py1':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(f) if 'f' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(f) else 'f', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert5 = @py_assert7 = None + + +def test_fetch_format(Subject): + """test fetch_format='frame'""" + with dj.config(fetch_format='frame'): + list1 = sorted(Subject.proj().fetch(as_dict=True), key=(itemgetter('subject_id'))) + list2 = sorted((Subject.fetch(dj.key)), key=(itemgetter('subject_id'))) + for l1, l2 in zip(list1, list2): + @py_assert1 = l1 == l2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (l1, l2)) % {'py0':@pytest_ar._saferepr(l1) if 'l1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l1) else 'l1', 'py2':@pytest_ar._saferepr(l2) if 'l2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l2) else 'l2'} + @py_format5 = (@pytest_ar._format_assertmsg('Primary key is not returned correctly') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert1 = None + + tmp = Subject.fetch(order_by='subject_id') + @py_assert3 = pandas.DataFrame + @py_assert5 = isinstance(tmp, @py_assert3) + if not @py_assert5: + @py_format7 = 'assert %(py6)s\n{%(py6)s = %(py0)s(%(py1)s, %(py4)s\n{%(py4)s = %(py2)s.DataFrame\n})\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py1':@pytest_ar._saferepr(tmp) if 'tmp' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(tmp) else 'tmp', 'py2':@pytest_ar._saferepr(pandas) if 'pandas' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pandas) else 'pandas', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert3 = @py_assert5 = None + tmp = tmp.to_records() + subject_notes, key, real_id = Subject.fetch('subject_notes', dj.key, 'real_id') + np.testing.assert_array_equal(sorted(subject_notes), sorted(tmp['subject_notes'])) + np.testing.assert_array_equal(sorted(real_id), sorted(tmp['real_id'])) + list1 = sorted(key, key=(itemgetter('subject_id'))) + for l1, l2 in zip(list1, list2): + @py_assert1 = l1 == l2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (l1, l2)) % {'py0':@pytest_ar._saferepr(l1) if 'l1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l1) else 'l1', 'py2':@pytest_ar._saferepr(l2) if 'l2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(l2) else 'l2'} + @py_format5 = (@pytest_ar._format_assertmsg('Primary key is not returned correctly') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert1 = None + + +def test_key_fetch1(Subject): + """test KEY fetch1 - issue #976""" + with dj.config(fetch_format='array'): + k1 = (Subject & 'subject_id=10').fetch1('KEY') + with dj.config(fetch_format='frame'): + k2 = (Subject & 'subject_id=10').fetch1('KEY') + @py_assert1 = k1 == k2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (k1, k2)) % {'py0':@pytest_ar._saferepr(k1) if 'k1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(k1) else 'k1', 'py2':@pytest_ar._saferepr(k2) if 'k2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(k2) else 'k2'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + + +def test_same_secondary_attribute(Child, Parent): + children = (Child * Parent().proj()).fetch()['name'] + @py_assert2 = len(children) + @py_assert5 = 1 + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(children) if 'children' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(children) else 'children', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + @py_assert0 = children[0] + @py_assert3 = 'Dan' + @py_assert2 = @py_assert0 == @py_assert3 + if not @py_assert2: + @py_format5 = @pytest_ar._call_reprcompare(('==', ), (@py_assert2,), ('%(py1)s == %(py4)s', ), (@py_assert0, @py_assert3)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert0 = @py_assert2 = @py_assert3 = None + + +def test_query_caching(TTest3): + os.mkdir(os.path.expanduser('~/dj_query_cache')) + with dj.config(query_cache=(os.path.expanduser('~/dj_query_cache'))): + conn = TTest3.connection + TTest3.insert([dict(key=(100 + i), value=(200 + i)) for i in range(2)]) + conn.set_query_cache(query_cache='main') + cached_res = TTest3().fetch() + try: + TTest3.insert([dict(key=(200 + i), value=(400 + i)) for i in range(2)]) + @py_assert0 = False + if not @py_assert0: + @py_format2 = (@pytest_ar._format_assertmsg('Insert allowed while query caching enabled') + '\n>assert %(py1)s') % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert0 = None + except dj.DataJointError: + conn.set_query_cache() + + TTest3.insert([dict(key=(600 + i), value=(800 + i)) for i in range(2)]) + conn.set_query_cache(query_cache='main') + previous_cache = TTest3().fetch() + @py_assert1 = [c == p for c, p in zip(cached_res, previous_cache)] + @py_assert3 = all(@py_assert1) + if not @py_assert3: + @py_format5 = 'assert %(py4)s\n{%(py4)s = %(py0)s(%(py2)s)\n}' % {'py0':@pytest_ar._saferepr(all) if 'all' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(all) else 'all', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = @py_assert3 = None + conn.set_query_cache() + uncached_res = TTest3().fetch() + @py_assert2 = len(uncached_res) + @py_assert7 = len(cached_res) + @py_assert4 = @py_assert2 > @py_assert7 + if not @py_assert4: + @py_format9 = @pytest_ar._call_reprcompare(('>', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} > %(py8)s\n{%(py8)s = %(py5)s(%(py6)s)\n}', ), (@py_assert2, @py_assert7)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(uncached_res) if 'uncached_res' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(uncached_res) else 'uncached_res', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py6':@pytest_ar._saferepr(cached_res) if 'cached_res' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(cached_res) else 'cached_res', 'py8':@pytest_ar._saferepr(@py_assert7)} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert2 = @py_assert4 = @py_assert7 = None + conn.purge_query_cache() + os.rmdir(os.path.expanduser('~/dj_query_cache')) + + +def test_fetch_group_by(Parent): + @py_assert1 = Parent() + @py_assert3 = @py_assert1.fetch + @py_assert5 = 'KEY' + @py_assert7 = 'name' + @py_assert9 = @py_assert3(@py_assert5, order_by=@py_assert7) + @py_assert12 = [ + {'parent_id': 1}] + @py_assert11 = @py_assert9 == @py_assert12 + if not @py_assert11: + @py_format14 = @pytest_ar._call_reprcompare(('==', ), (@py_assert11,), ('%(py10)s\n{%(py10)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s()\n}.fetch\n}(%(py6)s, order_by=%(py8)s)\n} == %(py13)s', ), (@py_assert9, @py_assert12)) % {'py0':@pytest_ar._saferepr(Parent) if 'Parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Parent) else 'Parent', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py13':@pytest_ar._saferepr(@py_assert12)} + @py_format16 = 'assert %(py15)s' % {'py15': @py_format14} + raise AssertionError(@pytest_ar._format_explanation(@py_format16)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = @py_assert12 = None + + +def test_dj_u_distinct(Stimulus): + contents = [ + (1, 2, 3), (2, 2, 3), (3, 3, 2), (4, 5, 5)] + Stimulus.insert(contents) + test_query = Stimulus() + result = dj.U('contrast', 'brightness') & test_query + expected_result = [ + {'contrast':2, + 'brightness':3}, + {'contrast':3, + 'brightness':2}, + {'contrast':5, + 'brightness':5}] + fetched_result = result.fetch(as_dict=True, order_by=('contrast', 'brightness')) + Stimulus.delete_quick() + @py_assert1 = fetched_result == expected_result + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (fetched_result, expected_result)) % {'py0':@pytest_ar._saferepr(fetched_result) if 'fetched_result' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(fetched_result) else 'fetched_result', 'py2':@pytest_ar._saferepr(expected_result) if 'expected_result' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(expected_result) else 'expected_result'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + + +def test_backslash(Parent): + expected = 'She\\Hulk' + Parent.insert([(2, expected)]) + q = Parent & dict(name=expected) + @py_assert1 = q.fetch1 + @py_assert3 = 'name' + @py_assert5 = @py_assert1(@py_assert3) + @py_assert7 = @py_assert5 == expected + if not @py_assert7: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.fetch1\n}(%(py4)s)\n} == %(py8)s', ), (@py_assert5, expected)) % {'py0':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(expected) if 'expected' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(expected) else 'expected'} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + q.delete() \ No newline at end of file diff --git a/tests/test_fetch_same.py b/tests/test_fetch_same.py new file mode 100644 index 000000000..f0dd4877a --- /dev/null +++ b/tests/test_fetch_same.py @@ -0,0 +1,118 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_fetch_same.py +# Compiled at: 2023-02-19 07:13:21 +# Size of source mod 2**32: 1723 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj, numpy as np, pytest +from . import PREFIX, connection_root, connection_test + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + '_fetch_same'), connection=connection_test) + yield schema + schema.drop() + + +@pytest.fixture +def ProjData(schema): + np.random.seed(700) + + @schema + class ProjData(dj.Lookup): + definition = '\n id : int\n ---\n resp : float\n sim : float\n big : longblob\n blah : varchar(10)\n ' + contents = [ + { + 'id': 0, 'resp': 20.33, 'sim': 45.324, 'big': 3, 'blah': 'yes'}, + {'id':1, + 'resp':94.3, + 'sim':34.23, + 'big':{'key1': np.random.randn(20, 10)}, + 'blah':'si'}, + {'id':2, + 'resp':1.9, + 'sim':10.23, + 'big':np.random.randn(4, 2), + 'blah':'sim'}] + + yield ProjData + ProjData.drop() + + +def test_object_conversion_one(ProjData): + new = ProjData.proj(sub='resp').fetch('sub') + @py_assert1 = new.dtype + @py_assert5 = np.float64 + @py_assert3 = @py_assert1 == @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.dtype\n} == %(py6)s\n{%(py6)s = %(py4)s.float64\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(new) if 'new' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(new) else 'new', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_object_conversion_two(ProjData): + sub, add = ProjData.proj(sub='resp', add='sim').fetch('sub', 'add') + @py_assert1 = sub.dtype + @py_assert5 = np.float64 + @py_assert3 = @py_assert1 == @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.dtype\n} == %(py6)s\n{%(py6)s = %(py4)s.float64\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(sub) if 'sub' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(sub) else 'sub', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + @py_assert1 = add.dtype + @py_assert5 = np.float64 + @py_assert3 = @py_assert1 == @py_assert5 + if not @py_assert3: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.dtype\n} == %(py6)s\n{%(py6)s = %(py4)s.float64\n}', ), (@py_assert1, @py_assert5)) % {'py0':@pytest_ar._saferepr(add) if 'add' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(add) else 'add', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_object_conversion_all(ProjData): + new = ProjData.proj(sub='resp', add='sim').fetch() + @py_assert0 = new['sub'] + @py_assert2 = @py_assert0.dtype + @py_assert6 = np.float64 + @py_assert4 = @py_assert2 == @py_assert6 + if not @py_assert4: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py1)s.dtype\n} == %(py7)s\n{%(py7)s = %(py5)s.float64\n}', ), (@py_assert2, @py_assert6)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert0 = @py_assert2 = @py_assert4 = @py_assert6 = None + @py_assert0 = new['add'] + @py_assert2 = @py_assert0.dtype + @py_assert6 = np.float64 + @py_assert4 = @py_assert2 == @py_assert6 + if not @py_assert4: + @py_format8 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py1)s.dtype\n} == %(py7)s\n{%(py7)s = %(py5)s.float64\n}', ), (@py_assert2, @py_assert6)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py7':@pytest_ar._saferepr(@py_assert6)} + @py_format10 = 'assert %(py9)s' % {'py9': @py_format8} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + @py_assert0 = @py_assert2 = @py_assert4 = @py_assert6 = None + + +def test_object_no_convert(ProjData): + new = ProjData.fetch() + @py_assert0 = new['big'] + @py_assert2 = @py_assert0.dtype + @py_assert5 = 'object' + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py1)s.dtype\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert0 = @py_assert2 = @py_assert4 = @py_assert5 = None + @py_assert0 = new['blah'] + @py_assert2 = @py_assert0.dtype + @py_assert5 = 'object' + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py1)s.dtype\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert0 = @py_assert2 = @py_assert4 = @py_assert5 = None \ No newline at end of file diff --git a/tests/test_filepath.py b/tests/test_filepath.py new file mode 100644 index 000000000..aefd452b7 --- /dev/null +++ b/tests/test_filepath.py @@ -0,0 +1,383 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_filepath.py +# Compiled at: 2023-02-19 16:10:10 +# Size of source mod 2**32: 9101 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +from pathlib import Path +import random, sys, io, logging, pytest +from . import connection_root, connection_test, bucket +from schemas.external import schema, stores, store_repo, store_repo_s3, Filepath, FilepathS3 +logger = logging.getLogger('datajoint') + +def test_path_match(schema, store_repo): + """test file path matches and empty file""" + store = store_repo + ext = schema.external[store] + stage_path = dj.config['stores'][store]['stage'] + relpath = 'path/to/films' + managed_file = Path(stage_path, relpath, 'vid.mov') + managed_file.parent.mkdir(parents=True, exist_ok=True) + open(str(managed_file), 'a').close() + uuid = ext.upload_filepath(str(managed_file)) + managed_file.unlink() + @py_assert1 = managed_file.exists + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = 'assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.exists\n}()\n}' % {'py0':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + @py_assert1 = {'hash': uuid} + @py_assert3 = ext & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'filepath' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert13 = managed_file.relative_to + @py_assert16 = @py_assert13(stage_path) + @py_assert18 = @py_assert16.as_posix + @py_assert20 = @py_assert18() + @py_assert22 = str(@py_assert20) + @py_assert10 = @py_assert8 == @py_assert22 + if not @py_assert10: + @py_format24 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py23)s\n{%(py23)s = %(py11)s(%(py21)s\n{%(py21)s = %(py19)s\n{%(py19)s = %(py17)s\n{%(py17)s = %(py14)s\n{%(py14)s = %(py12)s.relative_to\n}(%(py15)s)\n}.as_posix\n}()\n})\n}', ), (@py_assert8, @py_assert22)) % {'py0':@pytest_ar._saferepr(ext) if 'ext' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ext) else 'ext', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py12':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py14':@pytest_ar._saferepr(@py_assert13), 'py15':@pytest_ar._saferepr(stage_path) if 'stage_path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(stage_path) else 'stage_path', 'py17':@pytest_ar._saferepr(@py_assert16), 'py19':@pytest_ar._saferepr(@py_assert18), 'py21':@pytest_ar._saferepr(@py_assert20), 'py23':@pytest_ar._saferepr(@py_assert22)} + @py_format26 = 'assert %(py25)s' % {'py25': @py_format24} + raise AssertionError(@pytest_ar._format_explanation(@py_format26)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert13 = @py_assert16 = @py_assert18 = @py_assert20 = @py_assert22 = None + restored_path, checksum = ext.download_filepath(uuid) + @py_assert4 = str(managed_file) + @py_assert1 = restored_path == @py_assert4 + if not @py_assert1: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py5)s\n{%(py5)s = %(py2)s(%(py3)s)\n}', ), (restored_path, @py_assert4)) % {'py0':@pytest_ar._saferepr(restored_path) if 'restored_path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restored_path) else 'restored_path', 'py2':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py3':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert4 = None + @py_assert3 = dj.hash + @py_assert5 = @py_assert3.uuid_from_file + @py_assert9 = str(managed_file) + @py_assert11 = @py_assert5(@py_assert9) + @py_assert1 = checksum == @py_assert11 + if not @py_assert1: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py12)s\n{%(py12)s = %(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py2)s.hash\n}.uuid_from_file\n}(%(py10)s\n{%(py10)s = %(py7)s(%(py8)s)\n})\n}', ), (checksum, @py_assert11)) % {'py0':@pytest_ar._saferepr(checksum) if 'checksum' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(checksum) else 'checksum', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py7':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py8':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert9 = @py_assert11 = None + ext.delete(delete_external_files=True) + + +def test_filepath(schema, store_repo): + """test file management""" + random.seed('filepath') + store = store_repo + ext = schema.external[store] + stage_path = dj.config['stores'][store]['stage'] + filename = 'picture.dat' + relpath = 'one/two/three' + managed_file = Path(stage_path, relpath, filename) + managed_file.parent.mkdir(parents=True, exist_ok=True) + data = random.getrandbits(24000).to_bytes(3000, sys.byteorder) + with managed_file.open('wb') as f: + f.write(data) + uuid1 = ext.upload_filepath(str(managed_file)) + uuid2 = ext.upload_filepath(str(managed_file)) + @py_assert1 = uuid1 == uuid2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (uuid1, uuid2)) % {'py0':@pytest_ar._saferepr(uuid1) if 'uuid1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(uuid1) else 'uuid1', 'py2':@pytest_ar._saferepr(uuid2) if 'uuid2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(uuid2) else 'uuid2'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + managed_file.unlink() + @py_assert1 = managed_file.exists + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = 'assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.exists\n}()\n}' % {'py0':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + for _ in (1, 2): + restored_path, checksum = ext.download_filepath(uuid1) + @py_assert4 = str(managed_file) + @py_assert1 = restored_path == @py_assert4 + if not @py_assert1: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py5)s\n{%(py5)s = %(py2)s(%(py3)s)\n}', ), (restored_path, @py_assert4)) % {'py0':@pytest_ar._saferepr(restored_path) if 'restored_path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(restored_path) else 'restored_path', 'py2':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py3':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + else: + @py_assert1 = @py_assert4 = None + @py_assert3 = dj.hash + @py_assert5 = @py_assert3.uuid_from_file + @py_assert9 = str(managed_file) + @py_assert11 = @py_assert5(@py_assert9) + @py_assert1 = checksum == @py_assert11 + if not @py_assert1: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py12)s\n{%(py12)s = %(py6)s\n{%(py6)s = %(py4)s\n{%(py4)s = %(py2)s.hash\n}.uuid_from_file\n}(%(py10)s\n{%(py10)s = %(py7)s(%(py8)s)\n})\n}', ), (checksum, @py_assert11)) % {'py0':@pytest_ar._saferepr(checksum) if 'checksum' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(checksum) else 'checksum', 'py2':@pytest_ar._saferepr(dj) if 'dj' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(dj) else 'dj', 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py7':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py8':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert9 = @py_assert11 = None + + with managed_file.open('rb') as f: + synced_data = f.read() + @py_assert1 = data == synced_data + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data, synced_data)) % {'py0':@pytest_ar._saferepr(data) if 'data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data) else 'data', 'py2':@pytest_ar._saferepr(synced_data) if 'synced_data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(synced_data) else 'synced_data'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + ext.delete(delete_external_files=True) + @py_assert1 = ext.exists + @py_assert4 = ext._make_external_filepath + @py_assert10 = Path(relpath, filename) + @py_assert12 = str(@py_assert10) + @py_assert14 = @py_assert4(@py_assert12) + @py_assert16 = @py_assert1(@py_assert14) + @py_assert18 = not @py_assert16 + if not @py_assert18: + @py_format19 = 'assert not %(py17)s\n{%(py17)s = %(py2)s\n{%(py2)s = %(py0)s.exists\n}(%(py15)s\n{%(py15)s = %(py5)s\n{%(py5)s = %(py3)s._make_external_filepath\n}(%(py13)s\n{%(py13)s = %(py6)s(%(py11)s\n{%(py11)s = %(py7)s(%(py8)s, %(py9)s)\n})\n})\n})\n}' % {'py0':@pytest_ar._saferepr(ext) if 'ext' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ext) else 'ext', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(ext) if 'ext' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ext) else 'ext', 'py5':@pytest_ar._saferepr(@py_assert4), 'py6':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py7':@pytest_ar._saferepr(Path) if 'Path' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Path) else 'Path', 'py8':@pytest_ar._saferepr(relpath) if 'relpath' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(relpath) else 'relpath', 'py9':@pytest_ar._saferepr(filename) if 'filename' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(filename) else 'filename', 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12), 'py15':@pytest_ar._saferepr(@py_assert14), 'py17':@pytest_ar._saferepr(@py_assert16)} + raise AssertionError(@pytest_ar._format_explanation(@py_format19)) + @py_assert1 = @py_assert4 = @py_assert10 = @py_assert12 = @py_assert14 = @py_assert16 = @py_assert18 = None + + +def test_filepath_s3(schema, store_repo_s3): + """test file management with s3""" + test_filepath(schema, store_repo_s3) + + +def test_duplicate_upload(schema, store_repo): + random.seed('filepath') + store = store_repo + data = random.getrandbits(2400).to_bytes(300, sys.byteorder) + ext = schema.external[store] + stage_path = dj.config['stores'][store]['stage'] + relpath = 'one/two/three' + managed_file = Path(stage_path, relpath, 'plot.dat') + managed_file.parent.mkdir(parents=True, exist_ok=True) + with managed_file.open('wb') as f: + f.write(data) + ext.upload_filepath(str(managed_file)) + ext.upload_filepath(str(managed_file)) + + +def test_duplicate_upload_s3(schema, store_repo_s3): + test_duplicate_upload(schema, store_repo_s3) + + +def test_duplicate_error(schema, store_repo): + """syncing duplicate non-matching file should fail""" + random.seed('filepath') + store = store_repo + data1 = random.getrandbits(2400).to_bytes(300, sys.byteorder) + data2 = random.getrandbits(2400).to_bytes(300, sys.byteorder) + ext = schema.external[store] + stage_path = dj.config['stores'][store]['stage'] + relpath = 'one/two/three' + managed_file = Path(stage_path, relpath, 'thesis.dat') + managed_file.parent.mkdir(parents=True, exist_ok=True) + with managed_file.open('wb') as f: + f.write(data1) + ext.upload_filepath(str(managed_file)) + with managed_file.open('wb') as f: + f.write(data2) + with pytest.raises(dj.DataJointError): + ext.upload_filepath(str(managed_file)) + + +def test_duplicate_error_s3(schema, store_repo_s3): + test_duplicate_error(schema, store_repo_s3) + + +def test_filepath_class(Filepath, store_repo, verify_checksum=True): + random.seed('filepath') + store = store_repo + table = Filepath() + if not verify_checksum: + dj.config['filepath_checksum_size_limit'] = 0 + stage_path = dj.config['stores'][store]['stage'] + relative_path = 'one/two/three' + managed_file = Path(stage_path, relative_path, 'attachment.dat') + managed_file.parent.mkdir(parents=True, exist_ok=True) + data = random.getrandbits(24000).to_bytes(3000, sys.byteorder) + with managed_file.open('wb') as f: + f.write(data) + with managed_file.open('rb') as f: + contents = f.read() + @py_assert1 = data == contents + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data, contents)) % {'py0':@pytest_ar._saferepr(data) if 'data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data) else 'data', 'py2':@pytest_ar._saferepr(contents) if 'contents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(contents) else 'contents'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + table.insert1((1, str(managed_file))) + managed_file.unlink() + @py_assert1 = managed_file.is_file + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = 'assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.is_file\n}()\n}' % {'py0':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + filepath = (table & {'fnum': 1}).fetch1('img') + @py_assert4 = str(managed_file) + @py_assert1 = filepath == @py_assert4 + if not @py_assert1: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py5)s\n{%(py5)s = %(py2)s(%(py3)s)\n}', ), (filepath, @py_assert4)) % {'py0':@pytest_ar._saferepr(filepath) if 'filepath' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(filepath) else 'filepath', 'py2':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py3':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert4 = None + with managed_file.open('rb') as f: + contents = f.read() + @py_assert1 = data == contents + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data, contents)) % {'py0':@pytest_ar._saferepr(data) if 'data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data) else 'data', 'py2':@pytest_ar._saferepr(contents) if 'contents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(contents) else 'contents'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + table.delete() + @py_assert0 = table.external[store] + if not @py_assert0: + @py_format2 = 'assert %(py1)s' % {'py1': @pytest_ar._saferepr(@py_assert0)} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert0 = None + table.external[store].delete(delete_external_files=True) + dj.config['filepath_checksum_size_limit'] = None + + +def test_filepath_class_s3(FilepathS3, store_repo_s3): + test_filepath_class(FilepathS3, store_repo_s3) + + +def test_filepath_class_no_checksum(Filepath, store_repo): + log_capture = io.StringIO() + stream_handler = logging.StreamHandler(log_capture) + log_format = logging.Formatter('[%(asctime)s][%(funcName)s][%(levelname)s]: %(message)s') + stream_handler.setFormatter(log_format) + stream_handler.set_name('test_limit_warning') + logger.addHandler(stream_handler) + test_filepath_class(Filepath, store_repo, verify_checksum=False) + log_contents = log_capture.getvalue() + log_capture.close() + for handler in logger.handlers: + if handler.name == 'test_limit_warning': + logger.removeHandler(handler) + + @py_assert0 = 'Skipped checksum for file with hash:' + @py_assert2 = @py_assert0 in log_contents + if not @py_assert2: + @py_format4 = @pytest_ar._call_reprcompare(('in', ), (@py_assert2,), ('%(py1)s in %(py3)s', ), (@py_assert0, log_contents)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py3':@pytest_ar._saferepr(log_contents) if 'log_contents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(log_contents) else 'log_contents'} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert0 = @py_assert2 = None + + +def test_filepath_cleanup(schema, Filepath, store_repo): + """test deletion of filepath entries from external table""" + random.seed('filepath') + table = Filepath() + store = store_repo + stage_path = dj.config['stores'][store]['stage'] + n = 20 + contents = random.getrandbits(2760).to_bytes(345, sys.byteorder) + for i in range(n): + relative_path = Path(*random.sample(('one', 'two', 'three', 'four'), k=3)) + managed_file = Path(stage_path, relative_path, 'file.dat') + managed_file.parent.mkdir(parents=True, exist_ok=True) + with managed_file.open('wb') as f: + f.write(contents) + table.insert1((i, str(managed_file))) + + @py_assert2 = len(table) + @py_assert4 = @py_assert2 == n + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, n)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(table) if 'table' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table) else 'table', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + ext = schema.external[store] + @py_assert2 = len(table) + @py_assert4 = @py_assert2 == n + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, n)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(table) if 'table' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table) else 'table', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + @py_assert0 = 0 + @py_assert6 = len(ext) + @py_assert2 = @py_assert0 < @py_assert6 + @py_assert3 = @py_assert6 < n + if not (@py_assert2 and @py_assert3): + @py_format9 = @pytest_ar._call_reprcompare(('<', '<'), (@py_assert2, @py_assert3), ('%(py1)s < %(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n}', + '%(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n} < %(py8)s'), (@py_assert0, @py_assert6, n)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py5':@pytest_ar._saferepr(ext) if 'ext' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ext) else 'ext', 'py7':@pytest_ar._saferepr(@py_assert6), 'py8':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n'} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert0 = @py_assert2 = @py_assert3 = @py_assert6 = None + (table & 'fnum in (1, 2, 3, 4, 5, 6)').delete() + m = n - len(table) + @py_assert2 = 6 + @py_assert1 = m == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (m, @py_assert2)) % {'py0':@pytest_ar._saferepr(m) if 'm' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(m) else 'm', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + ext.delete(delete_external_files=True) + @py_assert0 = 0 + @py_assert6 = len(ext) + @py_assert2 = @py_assert0 < @py_assert6 + @py_assert10 = n - m + @py_assert3 = @py_assert6 <= @py_assert10 + if not (@py_assert2 and @py_assert3): + @py_format11 = @pytest_ar._call_reprcompare(('<', '<='), (@py_assert2, @py_assert3), ('%(py1)s < %(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n}', + '%(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n} <= (%(py8)s - %(py9)s)'), (@py_assert0, @py_assert6, @py_assert10)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py5':@pytest_ar._saferepr(ext) if 'ext' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ext) else 'ext', 'py7':@pytest_ar._saferepr(@py_assert6), 'py8':@pytest_ar._saferepr(n) if 'n' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(n) else 'n', 'py9':@pytest_ar._saferepr(m) if 'm' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(m) else 'm'} + @py_format13 = 'assert %(py12)s' % {'py12': @py_format11} + raise AssertionError(@pytest_ar._format_explanation(@py_format13)) + @py_assert0 = @py_assert2 = @py_assert3 = @py_assert6 = @py_assert10 = None + + +def test_filepath_cleanup_s3(schema, FilepathS3, store_repo_s3): + """test deletion of filepath entries from external table""" + test_filepath_cleanup(schema, FilepathS3, store_repo_s3) + + +def test_delete_without_files(schema, store_repo): + """test deletion of filepath entries from external table without removing files""" + schema.external[store_repo].delete(delete_external_files=False) + + +def test_return_string(Filepath, store_repo): + """test returning string on fetch""" + random.seed('filepath') + table = Filepath() + store = store_repo + stage_path = dj.config['stores'][store]['stage'] + relative_path = 'this/is/a/test' + managed_file = Path(stage_path, relative_path, 'string.dat') + managed_file.parent.mkdir(parents=True, exist_ok=True) + data = random.getrandbits(24000).to_bytes(3000, sys.byteorder) + with managed_file.open('wb') as f: + f.write(data) + with managed_file.open('rb') as f: + contents = f.read() + @py_assert1 = data == contents + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (data, contents)) % {'py0':@pytest_ar._saferepr(data) if 'data' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(data) else 'data', 'py2':@pytest_ar._saferepr(contents) if 'contents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(contents) else 'contents'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + table.insert1((138, str(managed_file))) + managed_file.unlink() + @py_assert1 = managed_file.is_file + @py_assert3 = @py_assert1() + @py_assert5 = not @py_assert3 + if not @py_assert5: + @py_format6 = 'assert not %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.is_file\n}()\n}' % {'py0':@pytest_ar._saferepr(managed_file) if 'managed_file' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(managed_file) else 'managed_file', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert3 = @py_assert5 = None + filepath = (table & {'fnum': 138}).fetch1('img') + @py_assert3 = isinstance(filepath, str) + if not @py_assert3: + @py_format5 = 'assert %(py4)s\n{%(py4)s = %(py0)s(%(py1)s, %(py2)s)\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py1':@pytest_ar._saferepr(filepath) if 'filepath' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(filepath) else 'filepath', 'py2':@pytest_ar._saferepr(str) if 'str' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(str) else 'str', 'py4':@pytest_ar._saferepr(@py_assert3)} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert3 = None \ No newline at end of file diff --git a/tests/test_foreign_keys.py b/tests/test_foreign_keys.py new file mode 100644 index 000000000..953ae14dc --- /dev/null +++ b/tests/test_foreign_keys.py @@ -0,0 +1,116 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_foreign_keys.py +# Compiled at: 2023-02-20 15:52:02 +# Size of source mod 2**32: 1561 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint.declare as declare +from . import connection_root, connection_test +from schemas.advanced import schema, Person, Parent, LocalSynapse, GlobalSynapse, Cell, Slice, Prep + +def test_aliased_fk(Person, Parent): + person = Person() + parent = Parent() + person.delete() + @py_assert1 = not person + if not @py_assert1: + @py_format2 = 'assert not %(py0)s' % {'py0': @pytest_ar._saferepr(person) if ('person' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(person)) else 'person'} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert1 = None + @py_assert1 = not parent + if not @py_assert1: + @py_format2 = 'assert not %(py0)s' % {'py0': @pytest_ar._saferepr(parent) if ('parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parent)) else 'parent'} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert1 = None + person.fill() + parent.fill() + if not person: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(person) if ('person' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(person)) else 'person'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + if not parent: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(parent) if ('parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parent)) else 'parent'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + link = person.proj(parent_name='full_name', parent='person_id') + parents = person * parent * link + parents &= dict(full_name='May K. Hall') + @py_assert2 = parents.fetch + @py_assert4 = 'parent_name' + @py_assert6 = @py_assert2(@py_assert4) + @py_assert8 = set(@py_assert6) + @py_assert11 = { + 'Hanna R. Walters', 'Russel S. James'} + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py0)s(%(py7)s\n{%(py7)s = %(py3)s\n{%(py3)s = %(py1)s.fetch\n}(%(py5)s)\n})\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(set) if 'set' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(set) else 'set', 'py1':@pytest_ar._saferepr(parents) if 'parents' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parents) else 'parents', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + delete_count = person.delete() + @py_assert2 = 16 + @py_assert1 = delete_count == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (delete_count, @py_assert2)) % {'py0':@pytest_ar._saferepr(delete_count) if 'delete_count' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(delete_count) else 'delete_count', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + + +def test_describe(schema, LocalSynapse, GlobalSynapse, Cell): + """real_definition should match original definition""" + for rel in (LocalSynapse, GlobalSynapse): + describe = rel.describe() + s1 = declare(rel.full_table_name, rel.definition, locals())[0].split('\n') + s2 = declare(rel.full_table_name, describe, locals())[0].split('\n') + for c1, c2 in zip(s1, s2): + @py_assert1 = c1 == c2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (c1, c2)) % {'py0':@pytest_ar._saferepr(c1) if 'c1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c1) else 'c1', 'py2':@pytest_ar._saferepr(c2) if 'c2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(c2) else 'c2'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + else: + @py_assert1 = None + + +def test_delete(Person, Parent): + person = Person() + parent = Parent() + person.delete() + @py_assert1 = not person + if not @py_assert1: + @py_format2 = 'assert not %(py0)s' % {'py0': @pytest_ar._saferepr(person) if ('person' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(person)) else 'person'} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert1 = None + @py_assert1 = not parent + if not @py_assert1: + @py_format2 = 'assert not %(py0)s' % {'py0': @pytest_ar._saferepr(parent) if ('parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parent)) else 'parent'} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert1 = None + person.fill() + parent.fill() + if not parent: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(parent) if ('parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parent)) else 'parent'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + original_len = len(parent) + to_delete = len(parent & '11 in (person_id, parent)') + (person & 'person_id=11').delete() + @py_assert1 = [] + @py_assert0 = to_delete + if to_delete: + @py_assert6 = len(parent) + @py_assert11 = original_len - to_delete + @py_assert8 = @py_assert6 == @py_assert11 + @py_assert0 = @py_assert8 + if not @py_assert0: + @py_format3 = '%(py2)s' % {'py2': @pytest_ar._saferepr(to_delete) if ('to_delete' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(to_delete)) else 'to_delete'} + @py_assert1.append(@py_format3) + if to_delete: + @py_format12 = @pytest_ar._call_reprcompare(('==', ), (@py_assert8,), ('%(py7)s\n{%(py7)s = %(py4)s(%(py5)s)\n} == (%(py9)s - %(py10)s)', ), (@py_assert6, @py_assert11)) % {'py4':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py5':@pytest_ar._saferepr(parent) if 'parent' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(parent) else 'parent', 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(original_len) if 'original_len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(original_len) else 'original_len', 'py10':@pytest_ar._saferepr(to_delete) if 'to_delete' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(to_delete) else 'to_delete'} + @py_format14 = '%(py13)s' % {'py13': @py_format12} + @py_assert1.append(@py_format14) + @py_format15 = @pytest_ar._format_boolop(@py_assert1, 0) % {} + @py_format17 = 'assert %(py16)s' % {'py16': @py_format15} + raise AssertionError(@pytest_ar._format_explanation(@py_format17)) + @py_assert0 = @py_assert1 = @py_assert6 = @py_assert8 = @py_assert11 = None \ No newline at end of file diff --git a/tests/test_groupby.py b/tests/test_groupby.py new file mode 100644 index 000000000..23597b929 --- /dev/null +++ b/tests/test_groupby.py @@ -0,0 +1,14 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_groupby.py +# Compiled at: 2023-02-20 15:56:32 +# Size of source mod 2**32: 656 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +from . import connection_root, connection_test +from schemas.simple import schema, A, D, L + +def test_aggr_with_proj(A, D): + A.aggr(D.proj(m='id_l'), ..., n='max(m) - min(m)') \ No newline at end of file diff --git a/tests/test_hash.py b/tests/test_hash.py new file mode 100644 index 000000000..22f64e3b7 --- /dev/null +++ b/tests/test_hash.py @@ -0,0 +1,34 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_hash.py +# Compiled at: 2023-02-20 15:57:14 +# Size of source mod 2**32: 209 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +from datajoint import hash + +def test_hash(): + @py_assert1 = hash.uuid_from_buffer + @py_assert3 = b'abc' + @py_assert5 = @py_assert1(@py_assert3) + @py_assert7 = @py_assert5.hex + @py_assert10 = '900150983cd24fb0d6963f7d28e17f72' + @py_assert9 = @py_assert7 == @py_assert10 + if not @py_assert9: + @py_format12 = @pytest_ar._call_reprcompare(('==', ), (@py_assert9,), ('%(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.uuid_from_buffer\n}(%(py4)s)\n}.hex\n} == %(py11)s', ), (@py_assert7, @py_assert10)) % {'py0':@pytest_ar._saferepr(hash) if 'hash' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(hash) else 'hash', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py11':@pytest_ar._saferepr(@py_assert10)} + @py_format14 = 'assert %(py13)s' % {'py13': @py_format12} + raise AssertionError(@pytest_ar._format_explanation(@py_format14)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert10 = None + @py_assert1 = hash.uuid_from_buffer + @py_assert3 = b'' + @py_assert5 = @py_assert1(@py_assert3) + @py_assert7 = @py_assert5.hex + @py_assert10 = 'd41d8cd98f00b204e9800998ecf8427e' + @py_assert9 = @py_assert7 == @py_assert10 + if not @py_assert9: + @py_format12 = @pytest_ar._call_reprcompare(('==', ), (@py_assert9,), ('%(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.uuid_from_buffer\n}(%(py4)s)\n}.hex\n} == %(py11)s', ), (@py_assert7, @py_assert10)) % {'py0':@pytest_ar._saferepr(hash) if 'hash' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(hash) else 'hash', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py11':@pytest_ar._saferepr(@py_assert10)} + @py_format14 = 'assert %(py13)s' % {'py13': @py_format12} + raise AssertionError(@pytest_ar._format_explanation(@py_format14)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert10 = None \ No newline at end of file diff --git a/tests/test_jobs.py b/tests/test_jobs.py new file mode 100644 index 000000000..01d528834 --- /dev/null +++ b/tests/test_jobs.py @@ -0,0 +1,262 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_jobs.py +# Compiled at: 2023-02-20 21:04:29 +# Size of source mod 2**32: 5081 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +from datajoint.jobs import ERROR_MESSAGE_LENGTH, TRUNCATION_APPENDIX +import string, random +from . import connection_root, connection_test +from schemas.default import schema, Subject, SigIntTable, SimpleSource, SigTermTable, ErrorClass, DjExceptionName + +def test_reserve_job(schema, Subject): + subjects = Subject() + schema.jobs.delete() + if not subjects: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(subjects) if ('subjects' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(subjects)) else 'subjects'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + table_name = 'fake_table' + for key in subjects.fetch('KEY'): + @py_assert1 = schema.jobs + @py_assert3 = @py_assert1.reserve + @py_assert7 = @py_assert3(table_name, key) + if not @py_assert7: + @py_format9 = (@pytest_ar._format_assertmsg('failed to reserve a job') + '\n>assert %(py8)s\n{%(py8)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.jobs\n}.reserve\n}(%(py5)s, %(py6)s)\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py5':@pytest_ar._saferepr(table_name) if 'table_name' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table_name) else 'table_name', 'py6':@pytest_ar._saferepr(key) if 'key' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key) else 'key', 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + else: + @py_assert1 = @py_assert3 = @py_assert7 = None + + for key in subjects.fetch('KEY'): + @py_assert1 = schema.jobs + @py_assert3 = @py_assert1.reserve + @py_assert7 = @py_assert3(table_name, key) + @py_assert9 = not @py_assert7 + if not @py_assert9: + @py_format10 = (@pytest_ar._format_assertmsg('failed to respect reservation') + '\n>assert not %(py8)s\n{%(py8)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.jobs\n}.reserve\n}(%(py5)s, %(py6)s)\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py5':@pytest_ar._saferepr(table_name) if 'table_name' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table_name) else 'table_name', 'py6':@pytest_ar._saferepr(key) if 'key' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key) else 'key', 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + else: + @py_assert1 = @py_assert3 = @py_assert7 = @py_assert9 = None + + for key in subjects.fetch('KEY'): + schema.jobs.complete(table_name, key) + + @py_assert1 = schema.jobs + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('failed to free jobs') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s.jobs\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + for key in subjects.fetch('KEY'): + @py_assert1 = schema.jobs + @py_assert3 = @py_assert1.reserve + @py_assert7 = @py_assert3(table_name, key) + if not @py_assert7: + @py_format9 = (@pytest_ar._format_assertmsg('failed to reserve new jobs') + '\n>assert %(py8)s\n{%(py8)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.jobs\n}.reserve\n}(%(py5)s, %(py6)s)\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py5':@pytest_ar._saferepr(table_name) if 'table_name' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table_name) else 'table_name', 'py6':@pytest_ar._saferepr(key) if 'key' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key) else 'key', 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + else: + @py_assert1 = @py_assert3 = @py_assert7 = None + + for key in subjects.fetch('KEY'): + schema.jobs.error(table_name, key, 'error message') + + for key in subjects.fetch('KEY'): + @py_assert1 = schema.jobs + @py_assert3 = @py_assert1.reserve + @py_assert7 = @py_assert3(table_name, key) + @py_assert9 = not @py_assert7 + if not @py_assert9: + @py_format10 = (@pytest_ar._format_assertmsg('failed to ignore error jobs') + '\n>assert not %(py8)s\n{%(py8)s = %(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.jobs\n}.reserve\n}(%(py5)s, %(py6)s)\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py5':@pytest_ar._saferepr(table_name) if 'table_name' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(table_name) else 'table_name', 'py6':@pytest_ar._saferepr(key) if 'key' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(key) else 'key', 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format10)) + else: + @py_assert1 = @py_assert3 = @py_assert7 = @py_assert9 = None + + (schema.jobs & dict(status='error')).delete() + @py_assert1 = schema.jobs + @py_assert3 = not @py_assert1 + if not @py_assert3: + @py_format4 = (@pytest_ar._format_assertmsg('failed to clear error jobs') + '\n>assert not %(py2)s\n{%(py2)s = %(py0)s.jobs\n}') % {'py0':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py2':@pytest_ar._saferepr(@py_assert1)} + raise AssertionError(@pytest_ar._format_explanation(@py_format4)) + @py_assert1 = @py_assert3 = None + + +def test_restrictions(schema): + jobs = schema.jobs + jobs.delete() + jobs.reserve('a', {'key': 'a1'}) + jobs.reserve('a', {'key': 'a2'}) + jobs.reserve('b', {'key': 'b1'}) + jobs.error('a', {'key': 'a2'}, 'error') + jobs.error('b', {'key': 'b1'}, 'error') + @py_assert2 = {'table_name': 'a'} + @py_assert4 = jobs & @py_assert2 + @py_assert5 = len(@py_assert4) + @py_assert8 = 2 + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s((%(py1)s & %(py3)s))\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(jobs) if 'jobs' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(jobs) else 'jobs', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert8 = None + @py_assert2 = {'status': 'error'} + @py_assert4 = jobs & @py_assert2 + @py_assert5 = len(@py_assert4) + @py_assert8 = 2 + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s((%(py1)s & %(py3)s))\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(jobs) if 'jobs' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(jobs) else 'jobs', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert8 = None + @py_assert2 = {'table_name':'a', 'status':'error'} + @py_assert4 = jobs & @py_assert2 + @py_assert5 = len(@py_assert4) + @py_assert8 = 1 + @py_assert7 = @py_assert5 == @py_assert8 + if not @py_assert7: + @py_format10 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py0)s((%(py1)s & %(py3)s))\n} == %(py9)s', ), (@py_assert5, @py_assert8)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(jobs) if 'jobs' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(jobs) else 'jobs', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5), 'py9':@pytest_ar._saferepr(@py_assert8)} + @py_format12 = 'assert %(py11)s' % {'py11': @py_format10} + raise AssertionError(@pytest_ar._format_explanation(@py_format12)) + @py_assert2 = @py_assert4 = @py_assert5 = @py_assert7 = @py_assert8 = None + jobs.delete() + + +def test_sigint(schema, SigIntTable): + schema.jobs.delete() + try: + SigIntTable().populate(reserve_jobs=True) + except KeyboardInterrupt: + pass + + status, error_message = schema.jobs.fetch1('status', 'error_message') + @py_assert2 = 'error' + @py_assert1 = status == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (status, @py_assert2)) % {'py0':@pytest_ar._saferepr(status) if 'status' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(status) else 'status', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + @py_assert2 = 'KeyboardInterrupt' + @py_assert1 = error_message == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (error_message, @py_assert2)) % {'py0':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + schema.jobs.delete() + + +def test_sigterm(schema, SigTermTable): + schema.jobs.delete() + try: + SigTermTable().populate(reserve_jobs=True) + except SystemExit: + pass + + status, error_message = schema.jobs.fetch1('status', 'error_message') + @py_assert2 = 'error' + @py_assert1 = status == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (status, @py_assert2)) % {'py0':@pytest_ar._saferepr(status) if 'status' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(status) else 'status', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + @py_assert2 = 'SystemExit: SIGTERM received' + @py_assert1 = error_message == @py_assert2 + if not @py_assert1: + @py_format4 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py3)s', ), (error_message, @py_assert2)) % {'py0':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py3':@pytest_ar._saferepr(@py_assert2)} + @py_format6 = 'assert %(py5)s' % {'py5': @py_format4} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert2 = None + schema.jobs.delete() + + +def test_suppress_dj_errors(schema, ErrorClass, DjExceptionName): + """test_suppress_dj_errors: dj errors suppressible w/o native py blobs""" + schema.jobs.delete() + ErrorClass.populate(reserve_jobs=True, suppress_errors=True) + @py_assert2 = DjExceptionName() + @py_assert4 = len(@py_assert2) + @py_assert10 = schema.jobs + @py_assert12 = len(@py_assert10) + @py_assert6 = @py_assert4 == @py_assert12 + @py_assert14 = 0 + @py_assert7 = @py_assert12 > @py_assert14 + if not (@py_assert6 and @py_assert7): + @py_format16 = @pytest_ar._call_reprcompare(('==', '>'), (@py_assert6, @py_assert7), ('%(py5)s\n{%(py5)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s()\n})\n} == %(py13)s\n{%(py13)s = %(py8)s(%(py11)s\n{%(py11)s = %(py9)s.jobs\n})\n}', + '%(py13)s\n{%(py13)s = %(py8)s(%(py11)s\n{%(py11)s = %(py9)s.jobs\n})\n} > %(py15)s'), (@py_assert4, @py_assert12, @py_assert14)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(DjExceptionName) if 'DjExceptionName' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(DjExceptionName) else 'DjExceptionName', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(@py_assert4), 'py8':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py9':@pytest_ar._saferepr(schema) if 'schema' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(schema) else 'schema', 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12), 'py15':@pytest_ar._saferepr(@py_assert14)} + @py_format18 = 'assert %(py17)s' % {'py17': @py_format16} + raise AssertionError(@pytest_ar._format_explanation(@py_format18)) + @py_assert2 = @py_assert4 = @py_assert6 = @py_assert7 = @py_assert10 = @py_assert12 = @py_assert14 = None + + +def test_long_error_message(schema, Subject): + random.seed('jobs') + subjects = Subject() + schema.jobs.delete() + long_error_message = ''.join((random.choice(string.ascii_letters) for _ in range(ERROR_MESSAGE_LENGTH + 100))) + short_error_message = ''.join((random.choice(string.ascii_letters) for _ in range(ERROR_MESSAGE_LENGTH // 2))) + if not subjects: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(subjects) if ('subjects' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(subjects)) else 'subjects'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + table_name = 'fake_table' + key = subjects.fetch('KEY')[0] + schema.jobs.reserve(table_name, key) + schema.jobs.error(table_name, key, long_error_message) + error_message = schema.jobs.fetch1('error_message') + @py_assert2 = len(error_message) + @py_assert4 = @py_assert2 == ERROR_MESSAGE_LENGTH + if not @py_assert4: + @py_format6 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py5)s', ), (@py_assert2, ERROR_MESSAGE_LENGTH)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py3':@pytest_ar._saferepr(@py_assert2), 'py5':@pytest_ar._saferepr(ERROR_MESSAGE_LENGTH) if 'ERROR_MESSAGE_LENGTH' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(ERROR_MESSAGE_LENGTH) else 'ERROR_MESSAGE_LENGTH'} + @py_format8 = (@pytest_ar._format_assertmsg('error message is longer than max allowed') + '\n>assert %(py7)s') % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert2 = @py_assert4 = None + @py_assert1 = error_message.endswith + @py_assert4 = @py_assert1(TRUNCATION_APPENDIX) + if not @py_assert4: + @py_format6 = (@pytest_ar._format_assertmsg('appropriate ending missing for truncated error message') + '\n>assert %(py5)s\n{%(py5)s = %(py2)s\n{%(py2)s = %(py0)s.endswith\n}(%(py3)s)\n}') % {'py0':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(TRUNCATION_APPENDIX) if 'TRUNCATION_APPENDIX' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TRUNCATION_APPENDIX) else 'TRUNCATION_APPENDIX', 'py5':@pytest_ar._saferepr(@py_assert4)} + raise AssertionError(@pytest_ar._format_explanation(@py_format6)) + @py_assert1 = @py_assert4 = None + schema.jobs.delete() + schema.jobs.reserve(table_name, key) + schema.jobs.error(table_name, key, short_error_message) + error_message = schema.jobs.fetch1('error_message') + @py_assert1 = error_message == short_error_message + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (error_message, short_error_message)) % {'py0':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py2':@pytest_ar._saferepr(short_error_message) if 'short_error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(short_error_message) else 'short_error_message'} + @py_format5 = (@pytest_ar._format_assertmsg('error messages do not agree') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + @py_assert1 = error_message.endswith + @py_assert4 = @py_assert1(TRUNCATION_APPENDIX) + @py_assert6 = not @py_assert4 + if not @py_assert6: + @py_format7 = (@pytest_ar._format_assertmsg('error message should not be truncated') + '\n>assert not %(py5)s\n{%(py5)s = %(py2)s\n{%(py2)s = %(py0)s.endswith\n}(%(py3)s)\n}') % {'py0':@pytest_ar._saferepr(error_message) if 'error_message' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_message) else 'error_message', 'py2':@pytest_ar._saferepr(@py_assert1), 'py3':@pytest_ar._saferepr(TRUNCATION_APPENDIX) if 'TRUNCATION_APPENDIX' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(TRUNCATION_APPENDIX) else 'TRUNCATION_APPENDIX', 'py5':@pytest_ar._saferepr(@py_assert4)} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert1 = @py_assert4 = @py_assert6 = None + schema.jobs.delete() + + +def test_long_error_stack(schema, Subject): + random.seed('jobs') + subjects = Subject() + schema.jobs.delete() + STACK_SIZE = 89942 + long_error_stack = ''.join((random.choice(string.ascii_letters) for _ in range(STACK_SIZE))) + if not subjects: + @py_format1 = 'assert %(py0)s' % {'py0': @pytest_ar._saferepr(subjects) if ('subjects' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(subjects)) else 'subjects'} + raise AssertionError(@pytest_ar._format_explanation(@py_format1)) + table_name = 'fake_table' + key = subjects.fetch('KEY')[0] + schema.jobs.reserve(table_name, key) + schema.jobs.error(table_name, key, 'error message', long_error_stack) + error_stack = schema.jobs.fetch1('error_stack') + @py_assert1 = error_stack == long_error_stack + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (error_stack, long_error_stack)) % {'py0':@pytest_ar._saferepr(error_stack) if 'error_stack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(error_stack) else 'error_stack', 'py2':@pytest_ar._saferepr(long_error_stack) if 'long_error_stack' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(long_error_stack) else 'long_error_stack'} + @py_format5 = (@pytest_ar._format_assertmsg('error stacks do not agree') + '\n>assert %(py4)s') % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + schema.jobs.delete() \ No newline at end of file diff --git a/tests/test_json.py b/tests/test_json.py new file mode 100644 index 000000000..f9974b069 --- /dev/null +++ b/tests/test_json.py @@ -0,0 +1,400 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_json.py +# Compiled at: 2023-02-20 16:46:34 +# Size of source mod 2**32: 7594 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj +import datajoint.declare as declare +from packaging import version +import numpy as np +from numpy.testing import assert_array_equal +import pytest +from . import PREFIX, connection_root, connection_test +if version.parse(dj.conn().query('select @@version;').fetchone()[0]) >= version.parse('8.0.0'): + + @pytest.fixture + def schema(connection_test): + schema = dj.Schema((PREFIX + '_json'), connection=connection_test) + yield schema + schema.drop() + + + @pytest.fixture + def Team(schema): + + @schema + class Team(dj.Lookup): + definition = "\n name: varchar(40)\n ---\n car=null: json\n unique index(car.name:char(20))\n uniQue inDex ( name, car.name:char(20), (json_value(`car`, _utf8mb4'$.length' returning decimal(4, 1))) )\n " + contents = [ + ( + 'engineering', + {'name':'Rever', + 'length':20.5, + 'inspected':True, + 'tire_pressure':[ + 32, 31, 33, 34], + 'headlights':[ + {'side':'left', + 'hyper_white':None}, + {'side':'right', + 'hyper_white':None}]}), + ( + 'business', + {'name':'Chaching', + 'length':100, + 'safety_inspected':False, + 'tire_pressure':[ + 34, 30, 27, 32], + 'headlights':[ + {'side':'left', + 'hyper_white':True}, + {'side':'right', + 'hyper_white':True}]}), + ('marketing', None)] + + yield Team + Team.drop() + + + def test_insert_update(Team): + car = {'name':'Discovery', + 'length':22.9, + 'inspected':None, + 'tire_pressure':[ + 35, 36, 34, 37], + 'headlights':[ + {'side':'left', + 'hyper_white':True}, + {'side':'right', + 'hyper_white':True}]} + Team.insert1({'name':'research', 'car':car}) + q = Team & {'name': 'research'} + @py_assert1 = q.fetch1 + @py_assert3 = 'car' + @py_assert5 = @py_assert1(@py_assert3) + @py_assert7 = @py_assert5 == car + if not @py_assert7: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.fetch1\n}(%(py4)s)\n} == %(py8)s', ), (@py_assert5, car)) % {'py0':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(car) if 'car' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(car) else 'car'} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + car.update({'length': 23}) + Team.update1({'name':'research', 'car':car}) + @py_assert1 = q.fetch1 + @py_assert3 = 'car' + @py_assert5 = @py_assert1(@py_assert3) + @py_assert7 = @py_assert5 == car + if not @py_assert7: + @py_format9 = @pytest_ar._call_reprcompare(('==', ), (@py_assert7,), ('%(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.fetch1\n}(%(py4)s)\n} == %(py8)s', ), (@py_assert5, car)) % {'py0':@pytest_ar._saferepr(q) if 'q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q) else 'q', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(car) if 'car' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(car) else 'car'} + @py_format11 = 'assert %(py10)s' % {'py10': @py_format9} + raise AssertionError(@pytest_ar._format_explanation(@py_format11)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + try: + Team.insert1({'name':'hr', 'car':car}) + raise Exception('Inserted non-unique car name.') + except dj.DataJointError: + pass + + q.delete_quick() + @py_assert1 = not q + if not @py_assert1: + @py_format2 = 'assert not %(py0)s' % {'py0': @pytest_ar._saferepr(q) if ('q' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(q)) else 'q'} + raise AssertionError(@pytest_ar._format_explanation(@py_format2)) + @py_assert1 = None + + + def test_describe(Team): + rel = Team() + context = locals() + s1 = declare(rel.full_table_name, rel.definition, context) + s2 = declare(rel.full_table_name, rel.describe(), context) + @py_assert1 = s1 == s2 + if not @py_assert1: + @py_format3 = @pytest_ar._call_reprcompare(('==', ), (@py_assert1,), ('%(py0)s == %(py2)s', ), (s1, s2)) % {'py0':@pytest_ar._saferepr(s1) if 's1' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s1) else 's1', 'py2':@pytest_ar._saferepr(s2) if 's2' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(s2) else 's2'} + @py_format5 = 'assert %(py4)s' % {'py4': @py_format3} + raise AssertionError(@pytest_ar._format_explanation(@py_format5)) + @py_assert1 = None + + + def test_restrict(Team): + @py_assert1 = {'car.name': 'Chaching'} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.length': 20.5} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'engineering' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.inspected': 'true'} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'engineering' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.inspected:unsigned': True} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'engineering' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.safety_inspected': 'false'} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.safety_inspected:unsigned': False} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.headlights[0].hyper_white': None} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch + @py_assert6 = 'name' + @py_assert8 = 'name' + @py_assert10 = True + @py_assert12 = @py_assert4(@py_assert6, order_by=@py_assert8, as_dict=@py_assert10) + @py_assert15 = [ + {'name': 'engineering'}, {'name': 'marketing'}] + @py_assert14 = @py_assert12 == @py_assert15 + if not @py_assert14: + @py_format17 = @pytest_ar._call_reprcompare(('==', ), (@py_assert14,), ('%(py13)s\n{%(py13)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch\n}(%(py7)s, order_by=%(py9)s, as_dict=%(py11)s)\n} == %(py16)s', ), (@py_assert12, @py_assert15)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12), 'py16':@pytest_ar._saferepr(@py_assert15)} + @py_format19 = 'assert %(py18)s' % {'py18': @py_format17} + raise AssertionError(@pytest_ar._format_explanation(@py_format19)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = @py_assert15 = None + @py_assert1 = {'car': None} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'marketing' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.tire_pressure': [34, 30, 27, 32]} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = {'car.headlights[1]': {'side':'right', 'hyper_white':True}} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = 'assert %(py14)s' % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "`car`->>'$.name' LIKE '%ching%'" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('Missing substring') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "`car`->>'$.length' > 30" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('<= 30') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "JSON_VALUE(`car`, '$.safety_inspected' RETURNING UNSIGNED) = 0" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('Has `safety_inspected` set to `true`') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "`car`->>'$.headlights[0].hyper_white' = 'null'" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'engineering' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('Has 1st `headlight` with `hyper_white` not set to `null`') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "`car`->>'$.inspected' IS NOT NULL" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'engineering' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('Missing `inspected` key') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = "`car`->>'$.tire_pressure' = '[34, 30, 27, 32]'" + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('`tire_pressure` array did not match') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + @py_assert1 = '`car`->>\'$.headlights[1]\' = \'{"side": "right", "hyper_white": true}\'' + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.fetch1 + @py_assert6 = 'name' + @py_assert8 = @py_assert4(@py_assert6) + @py_assert11 = 'business' + @py_assert10 = @py_assert8 == @py_assert11 + if not @py_assert10: + @py_format13 = @pytest_ar._call_reprcompare(('==', ), (@py_assert10,), ('%(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).fetch1\n}(%(py7)s)\n} == %(py12)s', ), (@py_assert8, @py_assert11)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py12':@pytest_ar._saferepr(@py_assert11)} + @py_format15 = (@pytest_ar._format_assertmsg('2nd `headlight` object did not match') + '\n>assert %(py14)s') % {'py14': @py_format13} + raise AssertionError(@pytest_ar._format_explanation(@py_format15)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert11 = None + + + def test_proj(Team): + @py_assert1 = Team.proj + @py_assert3 = 'car.length' + @py_assert5 = @py_assert1(car_length=@py_assert3) + @py_assert7 = @py_assert5.fetch + @py_assert9 = True + @py_assert11 = 'car_length' + @py_assert13 = @py_assert7(as_dict=@py_assert9, order_by=@py_assert11) + @py_assert16 = [ + {'name':'marketing', + 'car_length':None}, {'name':'business', 'car_length':'100'}, {'name':'engineering', 'car_length':'20.5'}] + @py_assert15 = @py_assert13 == @py_assert16 + if not @py_assert15: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert15,), ('%(py14)s\n{%(py14)s = %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.proj\n}(car_length=%(py4)s)\n}.fetch\n}(as_dict=%(py10)s, order_by=%(py12)s)\n} == %(py17)s', ), (@py_assert13, @py_assert16)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = @py_assert13 = @py_assert15 = @py_assert16 = None + @py_assert1 = Team.proj + @py_assert3 = 'car.length:decimal(4, 1)' + @py_assert5 = @py_assert1(car_length=@py_assert3) + @py_assert7 = @py_assert5.fetch + @py_assert9 = True + @py_assert11 = 'car_length' + @py_assert13 = @py_assert7(as_dict=@py_assert9, order_by=@py_assert11) + @py_assert16 = [ + {'name':'marketing', + 'car_length':None}, {'name':'engineering', 'car_length':20.5}, {'name':'business', 'car_length':100.0}] + @py_assert15 = @py_assert13 == @py_assert16 + if not @py_assert15: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert15,), ('%(py14)s\n{%(py14)s = %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.proj\n}(car_length=%(py4)s)\n}.fetch\n}(as_dict=%(py10)s, order_by=%(py12)s)\n} == %(py17)s', ), (@py_assert13, @py_assert16)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = @py_assert13 = @py_assert15 = @py_assert16 = None + @py_assert1 = Team.proj + @py_assert3 = "JSON_VALUE(`car`, '$.length' RETURNING float) - 15" + @py_assert5 = @py_assert1(car_width=@py_assert3) + @py_assert7 = @py_assert5.fetch + @py_assert9 = True + @py_assert11 = 'car_width' + @py_assert13 = @py_assert7(as_dict=@py_assert9, order_by=@py_assert11) + @py_assert16 = [ + {'name':'marketing', + 'car_width':None}, {'name':'engineering', 'car_width':5.5}, {'name':'business', 'car_width':85.0}] + @py_assert15 = @py_assert13 == @py_assert16 + if not @py_assert15: + @py_format18 = @pytest_ar._call_reprcompare(('==', ), (@py_assert15,), ('%(py14)s\n{%(py14)s = %(py8)s\n{%(py8)s = %(py6)s\n{%(py6)s = %(py2)s\n{%(py2)s = %(py0)s.proj\n}(car_width=%(py4)s)\n}.fetch\n}(as_dict=%(py10)s, order_by=%(py12)s)\n} == %(py17)s', ), (@py_assert13, @py_assert16)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7), 'py10':@pytest_ar._saferepr(@py_assert9), 'py12':@pytest_ar._saferepr(@py_assert11), 'py14':@pytest_ar._saferepr(@py_assert13), 'py17':@pytest_ar._saferepr(@py_assert16)} + @py_format20 = 'assert %(py19)s' % {'py19': @py_format18} + raise AssertionError(@pytest_ar._format_explanation(@py_format20)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = @py_assert9 = @py_assert11 = @py_assert13 = @py_assert15 = @py_assert16 = None + @py_assert1 = {'name': 'engineering'} + @py_assert3 = Team & @py_assert1 + @py_assert4 = @py_assert3.proj + @py_assert6 = 'car.tire_pressure' + @py_assert8 = @py_assert4(car_tire_pressure=@py_assert6) + @py_assert10 = @py_assert8.fetch1 + @py_assert12 = 'car_tire_pressure' + @py_assert14 = @py_assert10(@py_assert12) + @py_assert17 = '[32, 31, 33, 34]' + @py_assert16 = @py_assert14 == @py_assert17 + if not @py_assert16: + @py_format19 = @pytest_ar._call_reprcompare(('==', ), (@py_assert16,), ('%(py15)s\n{%(py15)s = %(py11)s\n{%(py11)s = %(py9)s\n{%(py9)s = %(py5)s\n{%(py5)s = (%(py0)s & %(py2)s).proj\n}(car_tire_pressure=%(py7)s)\n}.fetch1\n}(%(py13)s)\n} == %(py18)s', ), (@py_assert14, @py_assert17)) % {'py0':@pytest_ar._saferepr(Team) if 'Team' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(Team) else 'Team', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4), 'py7':@pytest_ar._saferepr(@py_assert6), 'py9':@pytest_ar._saferepr(@py_assert8), 'py11':@pytest_ar._saferepr(@py_assert10), 'py13':@pytest_ar._saferepr(@py_assert12), 'py15':@pytest_ar._saferepr(@py_assert14), 'py18':@pytest_ar._saferepr(@py_assert17)} + @py_format21 = 'assert %(py20)s' % {'py20': @py_format19} + raise AssertionError(@pytest_ar._format_explanation(@py_format21)) + @py_assert1 = @py_assert3 = @py_assert4 = @py_assert6 = @py_assert8 = @py_assert10 = @py_assert12 = @py_assert14 = @py_assert16 = @py_assert17 = None + assert_array_equal(Team.proj(car_inspected='car.inspected').fetch('car_inspected', + order_by='name'), np.array([None, 'true', None])) + assert_array_equal(Team.proj(car_inspected='car.inspected:unsigned').fetch('car_inspected', + order_by='name'), np.array([None, 1, None])) \ No newline at end of file diff --git a/tests/test_log.py b/tests/test_log.py new file mode 100644 index 000000000..a53a24304 --- /dev/null +++ b/tests/test_log.py @@ -0,0 +1,30 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_log.py +# Compiled at: 2023-02-20 16:50:06 +# Size of source mod 2**32: 274 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +from schemas.default import schema, Subject +from . import connection_root, connection_test + +def test_log(schema, Subject): + ts, events = (schema.log & 'event like "Declared%%"').fetch('timestamp', 'event') + @py_assert2 = len(events) + @py_assert5 = 1 + @py_assert4 = @py_assert2 == @py_assert5 + if not @py_assert4: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert4,), ('%(py3)s\n{%(py3)s = %(py0)s(%(py1)s)\n} == %(py6)s', ), (@py_assert2, @py_assert5)) % {'py0':@pytest_ar._saferepr(len) if 'len' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(len) else 'len', 'py1':@pytest_ar._saferepr(events) if 'events' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(events) else 'events', 'py3':@pytest_ar._saferepr(@py_assert2), 'py6':@pytest_ar._saferepr(@py_assert5)} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert4 = @py_assert5 = None + @py_assert0 = 'Declared' + @py_assert3 = events[0] + @py_assert2 = @py_assert0 in @py_assert3 + if not @py_assert2: + @py_format5 = @pytest_ar._call_reprcompare(('in', ), (@py_assert2,), ('%(py1)s in %(py4)s', ), (@py_assert0, @py_assert3)) % {'py1':@pytest_ar._saferepr(@py_assert0), 'py4':@pytest_ar._saferepr(@py_assert3)} + @py_format7 = 'assert %(py6)s' % {'py6': @py_format5} + raise AssertionError(@pytest_ar._format_explanation(@py_format7)) + @py_assert0 = @py_assert2 = @py_assert3 = None \ No newline at end of file diff --git a/tests/test_nan.py b/tests/test_nan.py new file mode 100644 index 000000000..386c17802 --- /dev/null +++ b/tests/test_nan.py @@ -0,0 +1,52 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_nan.py +# Compiled at: 2023-02-20 16:58:48 +# Size of source mod 2**32: 1293 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint as dj, numpy as np +from numpy.testing import assert_array_equal +import pytest +from . import PREFIX, connection_root, connection_test + +@pytest.fixture +def schema(connection_test): + schema = dj.Schema((PREFIX + '_nantest'), connection=connection_test) + yield schema + schema.drop() + + +expected = np.array([0, 0.3333333333333333, np.nan, np.pi, np.nan]) + +@pytest.fixture +def NanTest(schema): + + @schema + class NanTest(dj.Manual): + definition = '\n id :int\n ---\n value=null :double\n ' + + NanTest.insert(((i, value) for i, value in enumerate(expected))) + yield NanTest + NanTest.drop() + + +def test_insert_nan(NanTest): + """Test fetching of null values""" + fetched = NanTest.fetch('value', order_by='id') + assert_array_equal(np.isnan(fetched), np.isnan(expected), 'incorrect handling of Nans') + @py_assert1 = np.allclose + @py_assert3 = expected[np.logical_not(np.isnan(expected))] + @py_assert5 = fetched[np.logical_not(np.isnan(fetched))] + @py_assert7 = @py_assert1(@py_assert3, @py_assert5) + if not @py_assert7: + @py_format9 = (@pytest_ar._format_assertmsg('incorrect storage of floats') + '\n>assert %(py8)s\n{%(py8)s = %(py2)s\n{%(py2)s = %(py0)s.allclose\n}(%(py4)s, %(py6)s)\n}') % {'py0':@pytest_ar._saferepr(np) if 'np' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(np) else 'np', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = @py_assert7 = None + + +def test_nulls_do_not_affect_primary_keys(NanTest): + """Test against a case that previously caused a bug when skipping existing entries.""" + NanTest.insert(((i, value) for i, value in enumerate(expected)), skip_duplicates=True) \ No newline at end of file diff --git a/tests/test_plugin.py b/tests/test_plugin.py new file mode 100644 index 000000000..90eec3950 --- /dev/null +++ b/tests/test_plugin.py @@ -0,0 +1,94 @@ +# decompyle3 version 3.9.0 +# Python bytecode version base 3.7.0 (3394) +# Decompiled from: Python 3.7.17 (default, Jun 13 2023, 16:22:33) +# [GCC 10.2.1 20210110] +# Embedded file name: /workspaces/datajoint-python/tests/test_plugin.py +# Compiled at: 2023-02-20 17:00:15 +# Size of source mod 2**32: 1691 bytes +import builtins as @py_builtins +import _pytest.assertion.rewrite as @pytest_ar +import datajoint.errors as djerr +import datajoint.plugin as p +import pkg_resources +from os import path + +def test_check_pubkey(): + base_name = 'datajoint' + base_meta = pkg_resources.get_distribution(base_name) + pubkey_meta = base_meta.get_metadata('{}.pub'.format(base_name)) + with open(path.join(path.abspath(path.dirname(__file__)), '..', 'datajoint.pub'), 'r') as f: + @py_assert1 = f.read + @py_assert3 = @py_assert1() + @py_assert5 = @py_assert3 == pubkey_meta + if not @py_assert5: + @py_format7 = @pytest_ar._call_reprcompare(('==', ), (@py_assert5,), ('%(py4)s\n{%(py4)s = %(py2)s\n{%(py2)s = %(py0)s.read\n}()\n} == %(py6)s', ), (@py_assert3, pubkey_meta)) % {'py0':@pytest_ar._saferepr(f) if 'f' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(f) else 'f', 'py2':@pytest_ar._saferepr(@py_assert1), 'py4':@pytest_ar._saferepr(@py_assert3), 'py6':@pytest_ar._saferepr(pubkey_meta) if 'pubkey_meta' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(pubkey_meta) else 'pubkey_meta'} + @py_format9 = 'assert %(py8)s' % {'py8': @py_format7} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert1 = @py_assert3 = @py_assert5 = None + + +def test_normal_djerror(): + try: + raise djerr.DataJointError + except djerr.DataJointError as e: + try: + @py_assert1 = e.__cause__ + @py_assert4 = None + @py_assert3 = @py_assert1 is @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('is', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.__cause__\n} is %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(e) if 'e' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(e) else 'e', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + finally: + e = None + del e + + +def test_verified_djerror(category='connection'): + try: + curr_plugins = getattr(p, '{}_plugins'.format(category)) + setattr(p, '{}_plugins'.format(category), dict(test_plugin_id=dict(verified=True, object='example'))) + raise djerr.DataJointError + except djerr.DataJointError as e: + try: + setattr(p, '{}_plugins'.format(category), curr_plugins) + @py_assert1 = e.__cause__ + @py_assert4 = None + @py_assert3 = @py_assert1 is @py_assert4 + if not @py_assert3: + @py_format6 = @pytest_ar._call_reprcompare(('is', ), (@py_assert3,), ('%(py2)s\n{%(py2)s = %(py0)s.__cause__\n} is %(py5)s', ), (@py_assert1, @py_assert4)) % {'py0':@pytest_ar._saferepr(e) if 'e' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(e) else 'e', 'py2':@pytest_ar._saferepr(@py_assert1), 'py5':@pytest_ar._saferepr(@py_assert4)} + @py_format8 = 'assert %(py7)s' % {'py7': @py_format6} + raise AssertionError(@pytest_ar._format_explanation(@py_format8)) + @py_assert1 = @py_assert3 = @py_assert4 = None + finally: + e = None + del e + + +def test_verified_djerror_type(): + test_verified_djerror(category='type') + + +def test_unverified_djerror(category='connection'): + try: + curr_plugins = getattr(p, '{}_plugins'.format(category)) + setattr(p, '{}_plugins'.format(category), dict(test_plugin_id=dict(verified=False, object='example'))) + raise djerr.DataJointError('hello') + except djerr.DataJointError as e: + try: + setattr(p, '{}_plugins'.format(category), curr_plugins) + @py_assert2 = e.__cause__ + @py_assert5 = djerr.PluginWarning + @py_assert7 = isinstance(@py_assert2, @py_assert5) + if not @py_assert7: + @py_format9 = 'assert %(py8)s\n{%(py8)s = %(py0)s(%(py3)s\n{%(py3)s = %(py1)s.__cause__\n}, %(py6)s\n{%(py6)s = %(py4)s.PluginWarning\n})\n}' % {'py0':@pytest_ar._saferepr(isinstance) if 'isinstance' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(isinstance) else 'isinstance', 'py1':@pytest_ar._saferepr(e) if 'e' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(e) else 'e', 'py3':@pytest_ar._saferepr(@py_assert2), 'py4':@pytest_ar._saferepr(djerr) if 'djerr' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(djerr) else 'djerr', 'py6':@pytest_ar._saferepr(@py_assert5), 'py8':@pytest_ar._saferepr(@py_assert7)} + raise AssertionError(@pytest_ar._format_explanation(@py_format9)) + @py_assert2 = @py_assert5 = @py_assert7 = None + finally: + e = None + del e + + +def test_unverified_djerror_type(): + test_unverified_djerror(category='type') \ No newline at end of file diff --git a/tests/test_privileges.py b/tests/test_privileges.py new file mode 100644 index 000000000..5eb0a7bef --- /dev/null +++ b/tests/test_privileges.py @@ -0,0 +1,156 @@ +import datajoint as dj +import os +from packaging import version +import pytest +from . import PREFIX, connection_root, connection_test + +# from .schemas.default import schema, Language +from .schemas.privileges import ( + schema, + Parent, + Child, + NoAccess, + NoAccessAgain, +) + + +@pytest.fixture +def connection_view(connection_root): + """View user database connection.""" + target = f"`{PREFIX}%%`.*" + credentials = dict(host=os.getenv("DJ_HOST"), user="djview", password="djview") + permission = "SELECT" + + # Create MySQL users + if version.parse( + connection_root.query("select @@version;").fetchone()[0] + ) >= version.parse("8.0.0"): + # create user if necessary on mysql8 + connection_root.query( + f""" + CREATE USER IF NOT EXISTS '{credentials["user"]}'@'%%' + IDENTIFIED BY '{credentials["password"]}'; + """ + ) + connection_root.query( + f""" + GRANT {permission} ON {target} + TO '{credentials["user"]}'@'%%'; + """ + ) + else: + # grant permissions. For MySQL 5.7 this also automatically creates user + # if not exists + connection_root.query( + f""" + GRANT {permission} ON {target} + TO '{credentials["user"]}'@'%%' + IDENTIFIED BY '{credentials["password"]}'; + """ + ) + + connection = dj.Connection(**credentials) + yield connection + connection_root.query(f"""DROP USER `{credentials["user"]}`""") + connection.close() + + +def test_fail_create_schema(connection_view): + """creating a schema with no CREATE privilege""" + with pytest.raises(dj.DataJointError): + return dj.Schema("forbidden_schema", locals(), connection=connection_view) + + +# def test_insert_failure(schema, Language, connection_view): +# unprivileged = dj.Schema(schema.database, locals(), connection=connection_view) +# context = dict() +# unprivileged.spawn_missing_classes(context=context) +# assert issubclass(context["Language"], dj.Lookup) and len( +# context["Language"]() +# ) == len(Language()), "failed to spawn missing classes" +# with pytest.raises(dj.DataJointError): +# context["Language"]().insert1(("Socrates", "Greek")) + + +# def test_failure_to_create_table(schema, connection_view): +# unprivileged = dj.Schema(schema.database, locals(), connection=connection_view) + +# @unprivileged +# class Try(dj.Manual): +# definition = """ # should not matter really +# id : int +# --- +# value : float +# """ + +# with pytest.raises(dj.DataJointError): +# Try().insert1((1, 1.5)) + + +@pytest.fixture +def connection_subset(connection_root, schema, Parent, Child, NoAccess, NoAccessAgain): + """Subset user database connection.""" + + schema.activate( + f"{PREFIX}_pipeline", + connection=connection_root, + create_tables=True, + ) + credentials = dict(host=os.getenv("DJ_HOST"), user="djsubset", password="djsubset") + permission = "SELECT, INSERT, UPDATE, DELETE" + + # Create MySQL users + if version.parse( + connection_root.query("select @@version;").fetchone()[0] + ) >= version.parse("8.0.0"): + # create user if necessary on mysql8 + connection_root.query( + f""" + CREATE USER IF NOT EXISTS '{credentials["user"]}'@'%%' + IDENTIFIED BY '{credentials["password"]}'; + """ + ) + connection_root.query( + f""" + GRANT {permission} ON `{PREFIX}_pipeline`.`#parent` + TO '{credentials["user"]}'@'%%'; + """ + ) + connection_root.query( + f""" + GRANT {permission} ON `{PREFIX}_pipeline`.`__child` + TO '{credentials["user"]}'@'%%'; + """ + ) + else: + # grant permissions. For MySQL 5.7 this also automatically creates user + # if not exists + connection_root.query( + f""" + GRANT {permission} ON `{PREFIX}_pipeline`.`#parent` + TO '{credentials["user"]}'@'%%' + IDENTIFIED BY '{credentials["password"]}'; + """ + ) + connection_root.query( + f""" + GRANT {permission} ON `{PREFIX}_pipeline`.`__child` + TO '{credentials["user"]}'@'%%'; + """ + ) + + connection = dj.Connection(**credentials) + yield connection + connection_root.query(f"""DROP USER `{credentials["user"]}`""") + schema.drop() + connection.close() + + +def test_populate_activate(connection_subset): + pass + # importlib.reload(pipeline) + # pipeline.schema.activate( + # f"{PREFIX}_pipeline", create_schema=True, create_tables=False + # ) + # pipeline.Child.populate() + # assert pipeline.Child.progress(display=False)[0] == 0