From 1f56fa37d7882cb35188c0c9deb6f667144a2456 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 11 Nov 2016 12:22:44 -0500 Subject: [PATCH 1/4] WIP: metadata validation. --- lib/galaxy/tools/parameters/validation.py | 28 +++++++- test-data/1.csv | 80 ++++++++++++++++++++- test/functional/tools/metadata_check_eq.xml | 29 ++++++++ test/functional/tools/sample_tool_conf.xml | 1 + 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 test/functional/tools/metadata_check_eq.xml diff --git a/lib/galaxy/tools/parameters/validation.py b/lib/galaxy/tools/parameters/validation.py index 9af011260903..f13658d302f4 100644 --- a/lib/galaxy/tools/parameters/validation.py +++ b/lib/galaxy/tools/parameters/validation.py @@ -559,7 +559,32 @@ def validate(self, value, trans=None): super().validate(isinstance(value, model.DatasetInstance) and not missing, value_to_show=missing) -class UnspecifiedBuildValidator(Validator): +class MetadataEqualsValidator(Validator): + """ + """ + requires_dataset_metadata = True + + def __init__(self, metadata_name=None, value=None, message=None): + self.metadata_name = metadata_name + self.value = value + self.message = message or 'Metadata value for (%s) must be (%s) and is not.' % (metadata_name, value) + + @classmethod + def from_element(cls, param, elem): + return cls( + metadata_name=elem.get('metadata_name', None), + value=elem.get('value', None), + message=elem.get('message', None), + ) + + def validate( self, value, trans=None ): + if value: + metdata_value = getattr(value.metadata, self.metadata_name) + if metdata_value != self.value: + raise ValueError( self.message ) + + +class UnspecifiedBuildValidator( Validator ): """ Validator that checks for dbkey not equal to '?' @@ -949,6 +974,7 @@ def validate(self, value, trans=None): in_range=InRangeValidator, length=LengthValidator, metadata=MetadataValidator, + metadata_eq=MetadataEqualsValidator, unspecified_build=UnspecifiedBuildValidator, no_options=NoOptionsValidator, empty_field=EmptyTextfieldValidator, diff --git a/test-data/1.csv b/test-data/1.csv index 80d519fbe2d9..3e90e7cf1e99 100644 --- a/test-data/1.csv +++ b/test-data/1.csv @@ -1 +1,79 @@ -Transaction_date,Product,Price,Payment_Type,Name,City,State,Country,Account_Created,Last_Login,Latitude,Longitude 1/2/09 6:17,Product1,1200,Mastercard,carolina,Basildon,England,United Kingdom,1/2/09 6:00,1/2/09 6:08,51.5,-1.1166667 1/2/09 4:53,Product1,1200,Visa,Betina,Parkville ,MO,United States,1/2/09 4:42,1/2/09 7:49,39.195,-94.68194 1/2/09 13:08,Product1,1200,Mastercard,Federica e Andrea,Astoria ,OR,United States,1/1/09 16:21,1/3/09 12:32,46.18806,-123.83 1/3/09 14:44,Product1,1200,Visa,Gouya,Echuca,Victoria,Australia,9/25/05 21:13,1/3/09 14:22,-36.1333333,144.75 1/4/09 12:56,Product2,3600,Visa,Gerd W ,Cahaba Heights ,AL,United States,11/15/08 15:47,1/4/09 12:45,33.52056,-86.8025 1/4/09 13:19,Product1,1200,Visa,LAURENCE,Mickleton ,NJ,United States,9/24/08 15:19,1/4/09 13:04,39.79,-75.23806 1/4/09 20:11,Product1,1200,Mastercard,Fleur,Peoria ,IL,United States,1/3/09 9:38,1/4/09 19:45,40.69361,-89.58889 1/2/09 20:09,Product1,1200,Mastercard,adam,Martin ,TN,United States,1/2/09 17:43,1/4/09 20:01,36.34333,-88.85028 1/4/09 13:17,Product1,1200,Mastercard,Renee Elisabeth,Tel Aviv,Tel Aviv,Israel,1/4/09 13:03,1/4/09 22:10,32.0666667,34.7666667 1/4/09 14:11,Product1,1200,Visa,Aidan,Chatou,Ile-de-France,France,6/3/08 4:22,1/5/09 1:17,48.8833333,2.15 1/5/09 2:42,Product1,1200,Diners,Stacy,New York ,NY,United States,1/5/09 2:23,1/5/09 4:59,40.71417,-74.00639 1/5/09 5:39,Product1,1200,Amex,Heidi,Eindhoven,Noord-Brabant,Netherlands,1/5/09 4:55,1/5/09 8:15,51.45,5.4666667 1/2/09 9:16,Product1,1200,Mastercard,Sean ,Shavano Park ,TX,United States,1/2/09 8:32,1/5/09 9:05,29.42389,-98.49333 1/5/09 10:08,Product1,1200,Visa,Georgia,Eagle ,ID,United States,11/11/08 15:53,1/5/09 10:05,43.69556,-116.35306 1/2/09 14:18,Product1,1200,Visa,Richard,Riverside ,NJ,United States,12/9/08 12:07,1/5/09 11:01,40.03222,-74.95778 1/25/09 17:58,Product2,3600,Visa,carol,Ann Arbor ,MI,United States,7/5/08 9:20,2/7/09 18:51,42.27083,-83.72639 1/9/09 14:37,Product1,1200,Visa,Nona,South Jordan ,UT,United States,1/8/09 15:14,2/7/09 19:11,40.56222,-111.92889 1/25/09 2:46,Product2,3600,Visa,Family,Dubai,Dubayy,United Arab Emirates,1/8/09 1:19,2/8/09 2:06,25.2522222,55.28 1/17/09 20:46,Product2,3600,Visa,Michelle,Dubai,Dubayy,United Arab Emirates,4/13/08 2:36,2/8/09 2:12,25.2522222,55.28 1/24/09 7:18,Product2,3600,Visa,Kathryn,Kirriemuir,Scotland,United Kingdom,1/23/09 10:31,2/8/09 2:52,56.6666667,-3 1/11/09 7:09,Product1,1200,Visa,Oswald,Tramore,Waterford,Ireland,10/13/08 16:43,2/8/09 3:02,52.1588889,-7.1463889 1/8/09 4:15,Product1,1200,Visa,Elyssa,Gdansk,Pomorskie,Poland,1/7/09 15:00,2/8/09 3:50,54.35,18.6666667 1/22/09 10:47,Product1,1200,Visa,michelle,Arklow,Wicklow,Ireland,11/18/08 1:32,2/8/09 5:07,52.7930556,-6.1413889 1/26/09 20:47,Product1,1200,Mastercard,Alicia,Lincoln ,NE,United States,6/24/08 8:05,2/8/09 7:29,40.8,-96.66667 1/12/09 12:22,Product1,1200,Mastercard,JP,Tierp,Uppsala,Sweden,1/6/09 11:34,2/8/09 11:15,60.3333333,17.5 1/26/09 1:44,Product2,3600,Visa,Geraldine,Brussels,Brussels (Bruxelles),Belgium,1/31/08 13:28,2/8/09 14:39,50.8333333,4.3333333 1/18/09 12:57,Product1,1200,Mastercard,sandra,Burr Oak ,IA,United States,1/24/08 16:11,2/8/09 15:30,43.45889,-91.86528 1/24/09 21:26,Product1,1200,Visa,Olivia,Wheaton ,IL,United States,5/8/08 16:02,2/8/09 16:00,41.86611,-88.10694 1/26/09 12:26,Product2,3600,Mastercard,Tom,Killeen ,TX,United States,1/26/09 5:23,2/8/09 17:33,31.11694,-97.7275 1/5/09 7:37,Product1,1200,Visa,Annette ,Manhattan ,NY,United States,9/26/08 4:29,2/8/09 18:42,40.71417,-74.00639 1/14/09 12:33,Product1,1200,Visa,SUSAN,Oxford,England,United Kingdom,9/11/08 23:23,2/8/09 23:00,51.75,-1.25 1/14/09 0:15,Product2,3600,Visa,Michael,Paris,Ile-de-France,France,11/28/08 0:07,2/9/09 1:30,48.8666667,2.3333333 1/1/09 12:42,Product1,1200,Visa,ashton,Exeter,England,United Kingdom,12/15/08 1:16,2/9/09 2:52,50.7,-3.5333333 1/6/09 6:07,Product1,1200,Visa,Scott,Rungsted,Frederiksborg,Denmark,12/27/08 14:29,2/9/09 4:20,55.8841667,12.5419444 1/15/09 5:11,Product2,3600,Visa,Pam,London,England,United Kingdom,7/11/06 12:43,2/9/09 4:42,51.52721,0.14559 1/17/09 4:03,Product1,1200,Visa,Lisa ,Borja,Bohol,Philippines,1/17/09 2:45,2/9/09 6:09,9.9136111,124.0927778 1/19/09 10:13,Product2,3600,Mastercard,Pavel,London,England,United Kingdom,2/28/06 5:35,2/9/09 6:57,51.51334,-0.08895 1/18/09 9:42,Product1,1200,Visa,Richard,Jamestown ,RI,United States,1/18/09 9:22,2/9/09 8:30,41.49694,-71.36778 1/9/09 11:14,Product1,1200,Visa,Jasinta Jeanne,Owings Mills ,MD,United States,1/9/09 10:43,2/9/09 9:17,39.41944,-76.78056 1/10/09 13:42,Product1,1200,Visa,Rachel,Hamilton,Ontario,Canada,1/10/09 12:22,2/9/09 9:54,43.25,-79.8333333 1/7/09 7:28,Product1,1200,Amex,Cherish ,Anchorage ,AK,United States,7/28/08 7:31,2/9/09 10:50,61.21806,-149.90028 1/18/09 6:46,Product1,1200,Visa,Shona ,Mornington,Meath,Ireland,1/15/09 9:13,2/9/09 11:55,53.7233333,-6.2825 1/30/09 12:18,Product1,1200,Mastercard,Abikay,Fullerton ,CA,United States,1/26/09 13:34,2/9/09 12:53,33.87028,-117.92444 1/6/09 5:42,Product1,1200,Amex,Abikay,Atlanta ,GA,United States,10/27/08 14:16,2/9/09 13:50,33.74889,-84.38806 1/2/09 10:58,Product2,3600,Visa,Kendra,Toronto,Ontario,Canada,1/2/09 10:38,2/9/09 13:56,43.6666667,-79.4166667 1/8/09 3:29,Product1,1200,Visa,amanda,Liverpool,England,United Kingdom,12/22/08 1:41,2/9/09 14:06,53.4166667,-3 1/12/09 13:23,Product2,3600,Amex,Leila,Ponte San Nicolo,Veneto,Italy,9/13/05 8:42,2/9/09 14:09,45.3666667,11.6166667 1/19/09 9:34,Product1,1200,Amex,amanda,Las Vegas ,NV,United States,5/10/08 8:56,2/9/09 16:44,36.175,-115.13639 1/9/09 7:49,Product1,1200,Visa,Stacy,Rochester Hills ,MI,United States,7/28/08 7:18,2/9/09 17:41,42.68056,-83.13389 1/15/09 5:27,Product2,3600,Visa,Derrick,North Bay,Ontario,Canada,1/6/09 17:42,2/9/09 18:22,46.3,-79.45 1/8/09 23:40,Product1,1200,Visa,Jacob,Lindfield,New South Wales,Australia,1/8/09 17:52,2/9/09 18:31,-33.7833333,151.1666667 1/27/09 11:02,Product1,1200,Mastercard,DOREEN,Madrid,Madrid,Spain,1/24/09 8:21,2/9/09 18:42,40.4,-3.6833333 1/14/09 13:23,Product1,1200,Diners,eugenia,Wisconsin Rapids ,WI,United States,11/15/08 13:57,2/9/09 18:44,44.38361,-89.81722 1/7/09 20:01,Product1,1200,Visa,Karen,Austin ,TX,United States,1/6/09 19:16,2/9/09 19:56,30.26694,-97.74278 1/20/09 12:32,Product1,1200,Visa,Bea,Chicago ,IL,United States,1/16/09 19:08,2/9/09 20:42,41.85,-87.65 1/6/09 14:35,Product1,1200,Diners,Hilde Karin,Las Vegas ,NV,United States,12/17/08 11:59,2/9/09 22:59,36.175,-115.13639 1/4/09 6:51,Product1,1200,Visa,Rima,Mullingar,Westmeath,Ireland,1/3/09 12:34,2/10/09 0:59,53.5333333,-7.35 1/24/09 18:30,Product1,1200,Visa,Ruangrote,Melbourne,Victoria,Australia,7/17/08 5:19,2/10/09 2:12,-37.8166667,144.9666667 1/25/09 5:57,Product1,1200,Amex,pamela,Ayacucho,Buenos Aires,Argentina,1/24/09 9:29,2/10/09 6:38,-37.15,-58.4833333 1/5/09 10:02,Product2,3600,Visa,Emillie,Eagan ,MN,United States,1/5/09 9:03,2/10/09 7:29,44.80417,-93.16667 1/13/09 9:14,Product1,1200,Visa,sangeeta,Vossevangen,Hordaland,Norway,1/9/09 9:31,2/10/09 9:04,60.6333333,6.4333333 1/22/09 7:35,Product1,1200,Visa,Anja,Ferney-Voltaire,Rhone-Alpes,France,1/22/09 6:51,2/10/09 9:18,46.25,6.1166667 1/2/09 11:06,Product1,1200,Mastercard,Andrew,Sevilla,Andalucia,Spain,3/12/06 15:02,2/10/09 10:04,37.3772222,-5.9869444 1/11/09 9:50,Product1,1200,Visa,Bato,Munchengosserstadt,Thuringia,Germany,1/7/09 11:45,2/10/09 10:28,51.05,11.65 1/21/09 20:44,Product1,1200,Mastercard,Ailsa ,Lindenhurst ,NY,United States,1/21/09 7:47,2/10/09 10:51,40.68667,-73.37389 1/5/09 9:09,Product1,1200,Visa,Sophie,Bloomfield ,MI,United States,10/23/06 6:52,2/10/09 10:58,42.53778,-83.23306 1/5/09 12:41,Product1,1200,Visa,Katrin,Calgary,Alberta,Canada,12/3/08 14:49,2/10/09 11:45,51.0833333,-114.0833333 1/28/09 12:54,Product2,3600,Mastercard,Kelly ,Vancouver,British Columbia,Canada,1/27/09 21:04,2/10/09 12:09,49.25,-123.1333333 1/21/09 4:46,Product1,1200,Visa,Tomasz,Klampenborg,Kobenhavn,Denmark,6/10/08 11:25,2/10/09 12:22,55.7666667,12.6 1/7/09 13:28,Product1,1200,Visa,Elizabeth,Calne,England,United Kingdom,1/4/09 13:07,2/10/09 12:39,51.4333333,-2 1/27/09 11:18,Product2,3600,Amex,Michael,Los Angeles ,CA,United States,1/23/09 11:47,2/10/09 13:09,34.05222,-118.24278 1/7/09 12:39,Product2,3600,Visa,Natasha,Milano,Lombardy,Italy,6/2/06 13:01,2/10/09 13:19,45.4666667,9.2 1/24/09 13:54,Product2,3600,Mastercard,Meredith,Kloten,Zurich,Switzerland,1/24/09 12:30,2/10/09 13:47,47.45,8.5833333 1/30/09 6:48,Product1,1200,Mastercard,Nicole,Fayetteville ,NC,United States,1/30/09 4:51,2/10/09 14:41,35.0525,-78.87861 1/22/09 18:07,Product1,1200,Visa,Ryan,Simpsonville ,SC,United States,1/6/09 16:59,2/10/09 15:30,34.73694,-82.25444 1/29/09 15:03,Product1,1200,Visa,Mary ,Auckland,Auckland,New Zealand,2/9/06 11:14,2/10/09 16:31,-36.8666667,174.7666667 1/2/09 14:14,Product1,1200,Diners,Aaron,Reading,England,United Kingdom,11/16/08 15:49,2/10/09 16:38,51.4333333,-1 1/19/09 11:05,Product1,1200,Visa,Bertrand,North Caldwell ,NJ,United States,10/3/08 5:55,2/10/09 18:16,40.83972,-74.27694 \ No newline at end of file +Transaction_date,Product,Price,Payment_Type,Name,City,State,Country,Account_Created,Last_Login,Latitude,Longitude +1/2/09 6:17,Product1,1200,Mastercard,carolina,Basildon,England,United Kingdom,1/2/09 6:00,1/2/09 6:08,51.5,-1.1166667 +1/2/09 4:53,Product1,1200,Visa,Betina,Parkville ,MO,United States,1/2/09 4:42,1/2/09 7:49,39.195,-94.68194 +1/2/09 13:08,Product1,1200,Mastercard,Federica e Andrea,Astoria ,OR,United States,1/1/09 16:21,1/3/09 12:32,46.18806,-123.83 +1/3/09 14:44,Product1,1200,Visa,Gouya,Echuca,Victoria,Australia,9/25/05 21:13,1/3/09 14:22,-36.1333333,144.75 +1/4/09 12:56,Product2,3600,Visa,Gerd W ,Cahaba Heights ,AL,United States,11/15/08 15:47,1/4/09 12:45,33.52056,-86.8025 +1/4/09 13:19,Product1,1200,Visa,LAURENCE,Mickleton ,NJ,United States,9/24/08 15:19,1/4/09 13:04,39.79,-75.23806 +1/4/09 20:11,Product1,1200,Mastercard,Fleur,Peoria ,IL,United States,1/3/09 9:38,1/4/09 19:45,40.69361,-89.58889 +1/2/09 20:09,Product1,1200,Mastercard,adam,Martin ,TN,United States,1/2/09 17:43,1/4/09 20:01,36.34333,-88.85028 +1/4/09 13:17,Product1,1200,Mastercard,Renee Elisabeth,Tel Aviv,Tel Aviv,Israel,1/4/09 13:03,1/4/09 22:10,32.0666667,34.7666667 +1/4/09 14:11,Product1,1200,Visa,Aidan,Chatou,Ile-de-France,France,6/3/08 4:22,1/5/09 1:17,48.8833333,2.15 +1/5/09 2:42,Product1,1200,Diners,Stacy,New York ,NY,United States,1/5/09 2:23,1/5/09 4:59,40.71417,-74.00639 +1/5/09 5:39,Product1,1200,Amex,Heidi,Eindhoven,Noord-Brabant,Netherlands,1/5/09 4:55,1/5/09 8:15,51.45,5.4666667 +1/2/09 9:16,Product1,1200,Mastercard,Sean ,Shavano Park ,TX,United States,1/2/09 8:32,1/5/09 9:05,29.42389,-98.49333 +1/5/09 10:08,Product1,1200,Visa,Georgia,Eagle ,ID,United States,11/11/08 15:53,1/5/09 10:05,43.69556,-116.35306 +1/2/09 14:18,Product1,1200,Visa,Richard,Riverside ,NJ,United States,12/9/08 12:07,1/5/09 11:01,40.03222,-74.95778 +1/25/09 17:58,Product2,3600,Visa,carol,Ann Arbor ,MI,United States,7/5/08 9:20,2/7/09 18:51,42.27083,-83.72639 +1/9/09 14:37,Product1,1200,Visa,Nona,South Jordan ,UT,United States,1/8/09 15:14,2/7/09 19:11,40.56222,-111.92889 +1/25/09 2:46,Product2,3600,Visa,Family,Dubai,Dubayy,United Arab Emirates,1/8/09 1:19,2/8/09 2:06,25.2522222,55.28 +1/17/09 20:46,Product2,3600,Visa,Michelle,Dubai,Dubayy,United Arab Emirates,4/13/08 2:36,2/8/09 2:12,25.2522222,55.28 +1/24/09 7:18,Product2,3600,Visa,Kathryn,Kirriemuir,Scotland,United Kingdom,1/23/09 10:31,2/8/09 2:52,56.6666667,-3 +1/11/09 7:09,Product1,1200,Visa,Oswald,Tramore,Waterford,Ireland,10/13/08 16:43,2/8/09 3:02,52.1588889,-7.1463889 +1/8/09 4:15,Product1,1200,Visa,Elyssa,Gdansk,Pomorskie,Poland,1/7/09 15:00,2/8/09 3:50,54.35,18.6666667 +1/22/09 10:47,Product1,1200,Visa,michelle,Arklow,Wicklow,Ireland,11/18/08 1:32,2/8/09 5:07,52.7930556,-6.1413889 +1/26/09 20:47,Product1,1200,Mastercard,Alicia,Lincoln ,NE,United States,6/24/08 8:05,2/8/09 7:29,40.8,-96.66667 +1/12/09 12:22,Product1,1200,Mastercard,JP,Tierp,Uppsala,Sweden,1/6/09 11:34,2/8/09 11:15,60.3333333,17.5 +1/26/09 1:44,Product2,3600,Visa,Geraldine,Brussels,Brussels (Bruxelles),Belgium,1/31/08 13:28,2/8/09 14:39,50.8333333,4.3333333 +1/18/09 12:57,Product1,1200,Mastercard,sandra,Burr Oak ,IA,United States,1/24/08 16:11,2/8/09 15:30,43.45889,-91.86528 +1/24/09 21:26,Product1,1200,Visa,Olivia,Wheaton ,IL,United States,5/8/08 16:02,2/8/09 16:00,41.86611,-88.10694 +1/26/09 12:26,Product2,3600,Mastercard,Tom,Killeen ,TX,United States,1/26/09 5:23,2/8/09 17:33,31.11694,-97.7275 +1/5/09 7:37,Product1,1200,Visa,Annette ,Manhattan ,NY,United States,9/26/08 4:29,2/8/09 18:42,40.71417,-74.00639 +1/14/09 12:33,Product1,1200,Visa,SUSAN,Oxford,England,United Kingdom,9/11/08 23:23,2/8/09 23:00,51.75,-1.25 +1/14/09 0:15,Product2,3600,Visa,Michael,Paris,Ile-de-France,France,11/28/08 0:07,2/9/09 1:30,48.8666667,2.3333333 +1/1/09 12:42,Product1,1200,Visa,ashton,Exeter,England,United Kingdom,12/15/08 1:16,2/9/09 2:52,50.7,-3.5333333 +1/6/09 6:07,Product1,1200,Visa,Scott,Rungsted,Frederiksborg,Denmark,12/27/08 14:29,2/9/09 4:20,55.8841667,12.5419444 +1/15/09 5:11,Product2,3600,Visa,Pam,London,England,United Kingdom,7/11/06 12:43,2/9/09 4:42,51.52721,0.14559 +1/17/09 4:03,Product1,1200,Visa,Lisa ,Borja,Bohol,Philippines,1/17/09 2:45,2/9/09 6:09,9.9136111,124.0927778 +1/19/09 10:13,Product2,3600,Mastercard,Pavel,London,England,United Kingdom,2/28/06 5:35,2/9/09 6:57,51.51334,-0.08895 +1/18/09 9:42,Product1,1200,Visa,Richard,Jamestown ,RI,United States,1/18/09 9:22,2/9/09 8:30,41.49694,-71.36778 +1/9/09 11:14,Product1,1200,Visa,Jasinta Jeanne,Owings Mills ,MD,United States,1/9/09 10:43,2/9/09 9:17,39.41944,-76.78056 +1/10/09 13:42,Product1,1200,Visa,Rachel,Hamilton,Ontario,Canada,1/10/09 12:22,2/9/09 9:54,43.25,-79.8333333 +1/7/09 7:28,Product1,1200,Amex,Cherish ,Anchorage ,AK,United States,7/28/08 7:31,2/9/09 10:50,61.21806,-149.90028 +1/18/09 6:46,Product1,1200,Visa,Shona ,Mornington,Meath,Ireland,1/15/09 9:13,2/9/09 11:55,53.7233333,-6.2825 +1/30/09 12:18,Product1,1200,Mastercard,Abikay,Fullerton ,CA,United States,1/26/09 13:34,2/9/09 12:53,33.87028,-117.92444 +1/6/09 5:42,Product1,1200,Amex,Abikay,Atlanta ,GA,United States,10/27/08 14:16,2/9/09 13:50,33.74889,-84.38806 +1/2/09 10:58,Product2,3600,Visa,Kendra,Toronto,Ontario,Canada,1/2/09 10:38,2/9/09 13:56,43.6666667,-79.4166667 +1/8/09 3:29,Product1,1200,Visa,amanda,Liverpool,England,United Kingdom,12/22/08 1:41,2/9/09 14:06,53.4166667,-3 +1/12/09 13:23,Product2,3600,Amex,Leila,Ponte San Nicolo,Veneto,Italy,9/13/05 8:42,2/9/09 14:09,45.3666667,11.6166667 +1/19/09 9:34,Product1,1200,Amex,amanda,Las Vegas ,NV,United States,5/10/08 8:56,2/9/09 16:44,36.175,-115.13639 +1/9/09 7:49,Product1,1200,Visa,Stacy,Rochester Hills ,MI,United States,7/28/08 7:18,2/9/09 17:41,42.68056,-83.13389 +1/15/09 5:27,Product2,3600,Visa,Derrick,North Bay,Ontario,Canada,1/6/09 17:42,2/9/09 18:22,46.3,-79.45 +1/8/09 23:40,Product1,1200,Visa,Jacob,Lindfield,New South Wales,Australia,1/8/09 17:52,2/9/09 18:31,-33.7833333,151.1666667 +1/27/09 11:02,Product1,1200,Mastercard,DOREEN,Madrid,Madrid,Spain,1/24/09 8:21,2/9/09 18:42,40.4,-3.6833333 +1/14/09 13:23,Product1,1200,Diners,eugenia,Wisconsin Rapids ,WI,United States,11/15/08 13:57,2/9/09 18:44,44.38361,-89.81722 +1/7/09 20:01,Product1,1200,Visa,Karen,Austin ,TX,United States,1/6/09 19:16,2/9/09 19:56,30.26694,-97.74278 +1/20/09 12:32,Product1,1200,Visa,Bea,Chicago ,IL,United States,1/16/09 19:08,2/9/09 20:42,41.85,-87.65 +1/6/09 14:35,Product1,1200,Diners,Hilde Karin,Las Vegas ,NV,United States,12/17/08 11:59,2/9/09 22:59,36.175,-115.13639 +1/4/09 6:51,Product1,1200,Visa,Rima,Mullingar,Westmeath,Ireland,1/3/09 12:34,2/10/09 0:59,53.5333333,-7.35 +1/24/09 18:30,Product1,1200,Visa,Ruangrote,Melbourne,Victoria,Australia,7/17/08 5:19,2/10/09 2:12,-37.8166667,144.9666667 +1/25/09 5:57,Product1,1200,Amex,pamela,Ayacucho,Buenos Aires,Argentina,1/24/09 9:29,2/10/09 6:38,-37.15,-58.4833333 +1/5/09 10:02,Product2,3600,Visa,Emillie,Eagan ,MN,United States,1/5/09 9:03,2/10/09 7:29,44.80417,-93.16667 +1/13/09 9:14,Product1,1200,Visa,sangeeta,Vossevangen,Hordaland,Norway,1/9/09 9:31,2/10/09 9:04,60.6333333,6.4333333 +1/22/09 7:35,Product1,1200,Visa,Anja,Ferney-Voltaire,Rhone-Alpes,France,1/22/09 6:51,2/10/09 9:18,46.25,6.1166667 +1/2/09 11:06,Product1,1200,Mastercard,Andrew,Sevilla,Andalucia,Spain,3/12/06 15:02,2/10/09 10:04,37.3772222,-5.9869444 +1/11/09 9:50,Product1,1200,Visa,Bato,Munchengosserstadt,Thuringia,Germany,1/7/09 11:45,2/10/09 10:28,51.05,11.65 +1/21/09 20:44,Product1,1200,Mastercard,Ailsa ,Lindenhurst ,NY,United States,1/21/09 7:47,2/10/09 10:51,40.68667,-73.37389 +1/5/09 9:09,Product1,1200,Visa,Sophie,Bloomfield ,MI,United States,10/23/06 6:52,2/10/09 10:58,42.53778,-83.23306 +1/5/09 12:41,Product1,1200,Visa,Katrin,Calgary,Alberta,Canada,12/3/08 14:49,2/10/09 11:45,51.0833333,-114.0833333 +1/28/09 12:54,Product2,3600,Mastercard,Kelly ,Vancouver,British Columbia,Canada,1/27/09 21:04,2/10/09 12:09,49.25,-123.1333333 +1/21/09 4:46,Product1,1200,Visa,Tomasz,Klampenborg,Kobenhavn,Denmark,6/10/08 11:25,2/10/09 12:22,55.7666667,12.6 +1/7/09 13:28,Product1,1200,Visa,Elizabeth,Calne,England,United Kingdom,1/4/09 13:07,2/10/09 12:39,51.4333333,-2 +1/27/09 11:18,Product2,3600,Amex,Michael,Los Angeles ,CA,United States,1/23/09 11:47,2/10/09 13:09,34.05222,-118.24278 +1/7/09 12:39,Product2,3600,Visa,Natasha,Milano,Lombardy,Italy,6/2/06 13:01,2/10/09 13:19,45.4666667,9.2 +1/24/09 13:54,Product2,3600,Mastercard,Meredith,Kloten,Zurich,Switzerland,1/24/09 12:30,2/10/09 13:47,47.45,8.5833333 +1/30/09 6:48,Product1,1200,Mastercard,Nicole,Fayetteville ,NC,United States,1/30/09 4:51,2/10/09 14:41,35.0525,-78.87861 +1/22/09 18:07,Product1,1200,Visa,Ryan,Simpsonville ,SC,United States,1/6/09 16:59,2/10/09 15:30,34.73694,-82.25444 +1/29/09 15:03,Product1,1200,Visa,Mary ,Auckland,Auckland,New Zealand,2/9/06 11:14,2/10/09 16:31,-36.8666667,174.7666667 +1/2/09 14:14,Product1,1200,Diners,Aaron,Reading,England,United Kingdom,11/16/08 15:49,2/10/09 16:38,51.4333333,-1 +1/19/09 11:05,Product1,1200,Visa,Bertrand,North Caldwell ,NJ,United States,10/3/08 5:55,2/10/09 18:16,40.83972,-74.27694 diff --git a/test/functional/tools/metadata_check_eq.xml b/test/functional/tools/metadata_check_eq.xml new file mode 100644 index 000000000000..b156cbf89626 --- /dev/null +++ b/test/functional/tools/metadata_check_eq.xml @@ -0,0 +1,29 @@ + + Tests whether asserting metadata equals something works. + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/sample_tool_conf.xml b/test/functional/tools/sample_tool_conf.xml index 9aa784ae80f0..f2d3e7601d28 100644 --- a/test/functional/tools/sample_tool_conf.xml +++ b/test/functional/tools/sample_tool_conf.xml @@ -72,6 +72,7 @@ + From 12a4464b4875814892d24ba8ccd2d0c686d8a82f Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Sun, 19 Mar 2023 18:40:32 +0100 Subject: [PATCH 2/4] finish metadata equal validator --- lib/galaxy/tool_util/linters/inputs.py | 11 +++++ lib/galaxy/tool_util/xsd/galaxy.xsd | 10 ++++- lib/galaxy/tools/parameters/validation.py | 36 ++++++++++----- test/functional/tools/metadata_check_eq.xml | 50 ++++++++++++++++----- test/unit/tool_util/test_tool_linters.py | 10 ++++- 5 files changed, 92 insertions(+), 25 deletions(-) diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index 4721d5806447..5271bb8d23d4 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -32,6 +32,7 @@ ], "filename": ["dataset_metadata_in_file"], "metadata_name": [ + "dataset_metadata_equal", "dataset_metadata_in_data_table", "dataset_metadata_not_in_data_table", "dataset_metadata_in_file", @@ -51,6 +52,7 @@ "exclude_max": ["in_range", "dataset_metadata_in_range"], "split": ["dataset_metadata_in_file"], "skip": ["metadata"], + "value": ["dataset_metadata_equal"], } PARAMETER_VALIDATOR_TYPE_COMPATIBILITY = { @@ -61,6 +63,7 @@ "no_options", "unspecified_build", "dataset_ok_validator", + "dataset_metadata_equal", "dataset_metadata_in_range", "dataset_metadata_in_file", "dataset_metadata_in_data_table", @@ -72,6 +75,7 @@ "no_options", "unspecified_build", "dataset_ok_validator", + "dataset_metadata_equal", "dataset_metadata_in_range", "dataset_metadata_in_file", "dataset_metadata_in_data_table", @@ -392,6 +396,13 @@ def lint_inputs(tool_xml, lint_ctx): f"Parameter [{param_name}]: '{vtype}' validators need to define the 'min' or 'max' attribute(s)", node=validator, ) + if vtype in ["dataset_metadata_equal"] and ( + "value" not in validator.attrib or "metadata_name" not in validator.attrib + ): + lint_ctx.error( + f"Parameter [{param_name}]: '{vtype}' validators need to define the 'value' or 'metadata_name' attributes", + node=validator, + ) if vtype in ["metadata"] and ("check" not in validator.attrib and "skip" not in validator.attrib): lint_ctx.error( f"Parameter [{param_name}]: '{vtype}' validators need to define the 'check' or 'skip' attribute(s)", diff --git a/lib/galaxy/tool_util/xsd/galaxy.xsd b/lib/galaxy/tool_util/xsd/galaxy.xsd index ce54c99c2d67..8a638fe61d48 100644 --- a/lib/galaxy/tool_util/xsd/galaxy.xsd +++ b/lib/galaxy/tool_util/xsd/galaxy.xsd @@ -4408,6 +4408,7 @@ Note that each data parameter has automatically a metadata validator that checks if all non-optional metadata are set, i.e. `` + + + Value of the metadata to check. Only +applicable to ``dataset_metadata_equal``. + + Deprecated. Used to indicate lines in the file @@ -7064,6 +7071,7 @@ and ``bibtex`` are the only supported options. + diff --git a/lib/galaxy/tools/parameters/validation.py b/lib/galaxy/tools/parameters/validation.py index f13658d302f4..ba173a0df1e1 100644 --- a/lib/galaxy/tools/parameters/validation.py +++ b/lib/galaxy/tools/parameters/validation.py @@ -31,7 +31,7 @@ class Validator(abc.ABC): @classmethod def from_element(cls, param, elem): """ - Initialize the appropiate Validator class + Initialize the appropriate Validator class example call `validation.Validator.from_element(ToolParameter_object, Validator_object)` @@ -561,30 +561,42 @@ def validate(self, value, trans=None): class MetadataEqualsValidator(Validator): """ + Validator that checks for a metadata value for equality + + metadata values that are lists are converted as comma separated string + everything else is converted to the string representation """ + requires_dataset_metadata = True - def __init__(self, metadata_name=None, value=None, message=None): + def __init__(self, metadata_name=None, value=None, message=None, negate="false"): + if not message: + if not util.asbool(negate): + message = f"Metadata value for '{metadata_name}' must be '{value}', but it is '%s'." + else: + message = f"Metadata value for '{metadata_name}' must not be '{value}' but it is." + super().__init__(message, negate) self.metadata_name = metadata_name self.value = value - self.message = message or 'Metadata value for (%s) must be (%s) and is not.' % (metadata_name, value) @classmethod def from_element(cls, param, elem): return cls( - metadata_name=elem.get('metadata_name', None), - value=elem.get('value', None), - message=elem.get('message', None), + metadata_name=elem.get("metadata_name", None), + value=elem.get("value", None), + message=elem.get("message", None), + negate=elem.get("negate", "false"), ) - def validate( self, value, trans=None ): + def validate(self, value, trans=None): if value: - metdata_value = getattr(value.metadata, self.metadata_name) - if metdata_value != self.value: - raise ValueError( self.message ) + metadata_value = getattr(value.metadata, self.metadata_name) + if isinstance(metadata_value, list): + metadata_value = ",".join(metadata_value) + super().validate(str(metadata_value) == self.value, value_to_show=metadata_value) -class UnspecifiedBuildValidator( Validator ): +class UnspecifiedBuildValidator(Validator): """ Validator that checks for dbkey not equal to '?' @@ -974,7 +986,7 @@ def validate(self, value, trans=None): in_range=InRangeValidator, length=LengthValidator, metadata=MetadataValidator, - metadata_eq=MetadataEqualsValidator, + dataset_metadata_equal=MetadataEqualsValidator, unspecified_build=UnspecifiedBuildValidator, no_options=NoOptionsValidator, empty_field=EmptyTextfieldValidator, diff --git a/test/functional/tools/metadata_check_eq.xml b/test/functional/tools/metadata_check_eq.xml index b156cbf89626..1ad44071600c 100644 --- a/test/functional/tools/metadata_check_eq.xml +++ b/test/functional/tools/metadata_check_eq.xml @@ -1,29 +1,59 @@ - + + Tests whether asserting metadata equals something works. > '$output' && + #end if + #if $input + echo "columns $input.metadata.columns" >> '$output' && + echo "column_names $input.metadata.column_names" >> '$output' + #else + echo "columns $input_negate.metadata.columns" >> '$output' && + echo "column_names $input_negate.metadata.column_names" >> '$output' + #end if ]]> - - + + + + + + + - - + + + + - + - + + + + + + - + - + + + + + + + + + diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index e27a59536e7f..a928bb918199 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -390,7 +390,7 @@ - + @@ -401,8 +401,10 @@ + + @@ -1334,10 +1336,14 @@ def test_inputs_validator_incompatibilities(lint_ctx): "Parameter [param_name]: 'value_in_data_table' validators need to define the 'table_name' attribute" in lint_ctx.error_messages ) + assert ( + "Parameter [another_param_name]: attribute 'value' is incompatible with validator of type 'metadata'" + in lint_ctx.error_messages + ) assert len(lint_ctx.info_messages) == 1 assert not lint_ctx.valid_messages assert len(lint_ctx.warn_messages) == 1 - assert len(lint_ctx.error_messages) == 7 + assert len(lint_ctx.error_messages) == 8 def test_inputs_validator_correct(lint_ctx): From 0e059f854a63b2ff2a5c833229c975d132029d09 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 20 Mar 2023 17:04:46 +0100 Subject: [PATCH 3/4] add value_json --- lib/galaxy/tool_util/linters/inputs.py | 20 +++++++++++++------- lib/galaxy/tool_util/xsd/galaxy.xsd | 12 +++++++++--- lib/galaxy/tools/parameters/validation.py | 8 ++++---- test/functional/tools/metadata_check_eq.xml | 13 ++++++------- test/unit/tool_util/test_tool_linters.py | 7 ++++++- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index 5271bb8d23d4..a02b69ba73fd 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -53,6 +53,7 @@ "split": ["dataset_metadata_in_file"], "skip": ["metadata"], "value": ["dataset_metadata_equal"], + "value_json": ["dataset_metadata_equal"], } PARAMETER_VALIDATOR_TYPE_COMPATIBILITY = { @@ -396,13 +397,18 @@ def lint_inputs(tool_xml, lint_ctx): f"Parameter [{param_name}]: '{vtype}' validators need to define the 'min' or 'max' attribute(s)", node=validator, ) - if vtype in ["dataset_metadata_equal"] and ( - "value" not in validator.attrib or "metadata_name" not in validator.attrib - ): - lint_ctx.error( - f"Parameter [{param_name}]: '{vtype}' validators need to define the 'value' or 'metadata_name' attributes", - node=validator, - ) + if vtype in ["dataset_metadata_equal"]: + if not ("value" in validator.attrib or "value_json" in validator.attrib) or "metadata_name" not in validator.attrib: + lint_ctx.error( + f"Parameter [{param_name}]: '{vtype}' validators need to define the 'value'/'value_json' and 'metadata_name' attributes", + node=validator, + ) + if "value" in validator.attrib and "value_json" in validator.attrib: + lint_ctx.error( + f"Parameter [{param_name}]: '{vtype}' validators must not define the 'value' and the 'value_json' attributes", + node=validator, + ) + if vtype in ["metadata"] and ("check" not in validator.attrib and "skip" not in validator.attrib): lint_ctx.error( f"Parameter [{param_name}]: '{vtype}' validators need to define the 'check' or 'skip' attribute(s)", diff --git a/lib/galaxy/tool_util/xsd/galaxy.xsd b/lib/galaxy/tool_util/xsd/galaxy.xsd index 8a638fe61d48..5d9257ecae7f 100644 --- a/lib/galaxy/tool_util/xsd/galaxy.xsd +++ b/lib/galaxy/tool_util/xsd/galaxy.xsd @@ -4408,7 +4408,7 @@ Note that each data parameter has automatically a metadata validator that checks if all non-optional metadata are set, i.e. `` - Value of the metadata to check. Only -applicable to ``dataset_metadata_equal``. + Value to check the metadata against. Only +applicable to ``dataset_metadata_equal``. Mutually exclusive with ``value_json``. + + + + + JSON encoded value to check the metadata against. Only +applicable to ``dataset_metadata_equal``. Mutually exclusive with ``value``. diff --git a/lib/galaxy/tools/parameters/validation.py b/lib/galaxy/tools/parameters/validation.py index ba173a0df1e1..323dc66f955d 100644 --- a/lib/galaxy/tools/parameters/validation.py +++ b/lib/galaxy/tools/parameters/validation.py @@ -2,6 +2,7 @@ Classes related to parameter validation. """ import abc +import json import logging import os.path import re @@ -581,9 +582,10 @@ def __init__(self, metadata_name=None, value=None, message=None, negate="false") @classmethod def from_element(cls, param, elem): + value = elem.get("value", None) or json.loads(elem.get("value_json", "null")) return cls( metadata_name=elem.get("metadata_name", None), - value=elem.get("value", None), + value=value, message=elem.get("message", None), negate=elem.get("negate", "false"), ) @@ -591,9 +593,7 @@ def from_element(cls, param, elem): def validate(self, value, trans=None): if value: metadata_value = getattr(value.metadata, self.metadata_name) - if isinstance(metadata_value, list): - metadata_value = ",".join(metadata_value) - super().validate(str(metadata_value) == self.value, value_to_show=metadata_value) + super().validate(metadata_value == self.value, value_to_show=metadata_value) class UnspecifiedBuildValidator(Validator): diff --git a/test/functional/tools/metadata_check_eq.xml b/test/functional/tools/metadata_check_eq.xml index 1ad44071600c..9c8e3aeaf7eb 100644 --- a/test/functional/tools/metadata_check_eq.xml +++ b/test/functional/tools/metadata_check_eq.xml @@ -15,12 +15,12 @@ ]]> - - + + - - + + @@ -36,8 +36,7 @@ - - + @@ -48,7 +47,7 @@ - + diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index a928bb918199..cbe557b74fa7 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -391,6 +391,7 @@ + @@ -1340,10 +1341,14 @@ def test_inputs_validator_incompatibilities(lint_ctx): "Parameter [another_param_name]: attribute 'value' is incompatible with validator of type 'metadata'" in lint_ctx.error_messages ) + assert ( + "Parameter [another_param_name]: 'dataset_metadata_equal' validators must not define the 'value' and the 'value_json' attributes" + in lint_ctx.error_messages + ) assert len(lint_ctx.info_messages) == 1 assert not lint_ctx.valid_messages assert len(lint_ctx.warn_messages) == 1 - assert len(lint_ctx.error_messages) == 8 + assert len(lint_ctx.error_messages) == 9 def test_inputs_validator_correct(lint_ctx): From 6bd654cd20844ec4839a92608f5cb238f9d0a514 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Thu, 22 Jun 2023 10:07:10 +0200 Subject: [PATCH 4/4] fix black formatting --- lib/galaxy/tool_util/linters/inputs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index a02b69ba73fd..983f954cad5a 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -398,7 +398,10 @@ def lint_inputs(tool_xml, lint_ctx): node=validator, ) if vtype in ["dataset_metadata_equal"]: - if not ("value" in validator.attrib or "value_json" in validator.attrib) or "metadata_name" not in validator.attrib: + if ( + not ("value" in validator.attrib or "value_json" in validator.attrib) + or "metadata_name" not in validator.attrib + ): lint_ctx.error( f"Parameter [{param_name}]: '{vtype}' validators need to define the 'value'/'value_json' and 'metadata_name' attributes", node=validator,