|
4 | 4 | import datetime
|
5 | 5 |
|
6 | 6 | import numpy as np
|
7 |
| -from nose.tools import assert_equal, assert_false, assert_true, raises, assert_set_equal, assert_list_equal |
| 7 | +from nose.tools import (assert_equal, assert_false, assert_true, raises, assert_set_equal, |
| 8 | + assert_list_equal) |
8 | 9 |
|
9 | 10 | import datajoint as dj
|
10 | 11 | from .schema_simple import (A, B, D, E, F, L, DataA, DataB, TTestUpdate, IJ, JI,
|
@@ -159,6 +160,76 @@ def test_issue_376():
|
159 | 160 | def test_issue_463():
|
160 | 161 | assert_equal(((A & B) * B).fetch().size, len(A * B))
|
161 | 162 |
|
| 163 | + @staticmethod |
| 164 | + def test_issue_898(): |
| 165 | + # https://github.com/datajoint/datajoint-python/issues/898 |
| 166 | + schema = dj.schema('djtest_raphael') |
| 167 | + |
| 168 | + @schema |
| 169 | + class Subject(dj.Lookup): |
| 170 | + definition = """ |
| 171 | + subject_id: varchar(32) |
| 172 | + --- |
| 173 | + dob : date |
| 174 | + sex : enum('M', 'F', 'U') |
| 175 | + """ |
| 176 | + contents = [ |
| 177 | + ('mouse1', '2020-09-01', 'M'), |
| 178 | + ('mouse2', '2020-03-19', 'F'), |
| 179 | + ('mouse3', '2020-08-23', 'F') |
| 180 | + ] |
| 181 | + |
| 182 | + @schema |
| 183 | + class Session(dj.Lookup): |
| 184 | + definition = """ |
| 185 | + -> Subject |
| 186 | + session_start_time: datetime |
| 187 | + --- |
| 188 | + session_dir='' : varchar(32) |
| 189 | + """ |
| 190 | + contents = [ |
| 191 | + ('mouse1', '2020-12-01 12:32:34', ''), |
| 192 | + ('mouse1', '2020-12-02 12:32:34', ''), |
| 193 | + ('mouse1', '2020-12-03 12:32:34', ''), |
| 194 | + ('mouse1', '2020-12-04 12:32:34', '') |
| 195 | + ] |
| 196 | + |
| 197 | + @schema |
| 198 | + class SessionStatus(dj.Lookup): |
| 199 | + definition = """ |
| 200 | + -> Session |
| 201 | + --- |
| 202 | + status: enum('in_training', 'trained_1a', 'trained_1b', 'ready4ephys') |
| 203 | + """ |
| 204 | + contents = [ |
| 205 | + ('mouse1', '2020-12-01 12:32:34', 'in_training'), |
| 206 | + ('mouse1', '2020-12-02 12:32:34', 'trained_1a'), |
| 207 | + ('mouse1', '2020-12-03 12:32:34', 'trained_1b'), |
| 208 | + ('mouse1', '2020-12-04 12:32:34', 'ready4ephys'), |
| 209 | + ] |
| 210 | + |
| 211 | + @schema |
| 212 | + class SessionDate(dj.Lookup): |
| 213 | + definition = """ |
| 214 | + -> Subject |
| 215 | + session_date: date |
| 216 | + """ |
| 217 | + contents = [ |
| 218 | + ('mouse1', '2020-12-01'), |
| 219 | + ('mouse1', '2020-12-02'), |
| 220 | + ('mouse1', '2020-12-03'), |
| 221 | + ('mouse1', '2020-12-04') |
| 222 | + ] |
| 223 | + |
| 224 | + subjects = Subject.aggr( |
| 225 | + SessionStatus & 'status="trained_1a" or status="trained_1b"', |
| 226 | + date_trained='min(date(session_start_time))') |
| 227 | + |
| 228 | + print(f'subjects: {subjects}') |
| 229 | + print(f'SessionDate: {SessionDate()}') |
| 230 | + print(f'join: {SessionDate * subjects}') |
| 231 | + print(f'join query: {(SessionDate * subjects).make_sql()}') |
| 232 | + |
162 | 233 | @staticmethod
|
163 | 234 | def test_project():
|
164 | 235 | x = A().proj(a='id_a') # rename
|
@@ -467,6 +538,12 @@ def test_complex_date_restriction():
|
467 | 538 | """Test a complex date restriction"""
|
468 | 539 | q = OutfitLaunch & 'day between curdate() - interval 30 day and curdate()'
|
469 | 540 | assert len(q) == 1
|
| 541 | + q = OutfitLaunch & 'day between curdate() - interval 4 week and curdate()' |
| 542 | + assert len(q) == 1 |
| 543 | + q = OutfitLaunch & 'day between curdate() - interval 1 month and curdate()' |
| 544 | + assert len(q) == 1 |
| 545 | + q = OutfitLaunch & 'day between curdate() - interval 1 year and curdate()' |
| 546 | + assert len(q) == 1 |
470 | 547 | q = OutfitLaunch & '`day` between curdate() - interval 30 day and curdate()'
|
471 | 548 | assert len(q) == 1
|
472 | 549 | q.delete()
|
|
0 commit comments