Skip to content

Commit

Permalink
Fix tests to adjust for ping mode being the default.
Browse files Browse the repository at this point in the history
 - Remove special ping ard object
 - Fix for `lg` (ARS) mode in `ping` mode
 - Remove duplicate tests in .json
  • Loading branch information
pbashyal-nmdp committed May 21, 2024
1 parent 5d1511e commit 87eece1
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 38 deletions.
34 changes: 25 additions & 9 deletions pyard/ard.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,28 @@ def _redux_allele(
# 2-field version first then re-reduce it to P group.
if redux_type in ("lg", "lgx", "U2"):
if allele in self.ars_mappings.p_not_g:
return self.ars_mappings.p_not_g[allele]
not_g_allele = self.ars_mappings.p_not_g[allele]
if redux_type == "lg":
return self._add_lg_suffix(not_g_allele)
return not_g_allele
else:
redux_allele = self._redux_allele(allele, redux_type, False)
if redux_allele.endswith("g"):
no_suffix_allele = redux_allele.removesuffix("g")
elif redux_allele.endswith("ARS"):
no_suffix_allele = redux_allele.removesuffix("ARS")
else:
no_suffix_allele = redux_allele
if (
redux_allele == allele
or redux_allele in self.ars_mappings.p_not_g.values()
no_suffix_allele == allele
or no_suffix_allele in self.ars_mappings.p_not_g.values()
):
return redux_allele
return self._redux_allele(redux_allele, "lgx", True)
redux_allele = self._redux_allele(
no_suffix_allele, redux_type, True
)
if self._is_valid_allele(redux_allele):
return redux_allele

if redux_type == "G" and allele in self.ars_mappings.g_group:
if allele in self.ars_mappings.dup_g:
Expand All @@ -238,11 +251,7 @@ def _redux_allele(
# return allele with only first 2 field
redux_allele = ":".join(allele.split(":")[0:2])
if redux_type == "lg":
# ARS suffix maybe used instead of g
if self._config["ARS_as_lg"]:
return redux_allele + "ARS"
# lg mode has g appended with lgx reduction
return redux_allele + "g"
return self._add_lg_suffix(redux_allele)
return redux_allele
elif redux_type == "W":
# new redux_type which is full WHO expansion
Expand Down Expand Up @@ -328,6 +337,13 @@ def _redux_allele(
else:
raise InvalidAlleleError(f"{allele} is an invalid allele.")

def _add_lg_suffix(self, redux_allele):
# ARS suffix maybe used instead of g
if self._config["ARS_as_lg"]:
return redux_allele + "ARS"
# lg mode has g appended with lgx reduction
return redux_allele + "g"

def _get_non_strict_allele(self, allele):
"""
In non-strict mode, if the allele is not valid,
Expand Down
6 changes: 0 additions & 6 deletions tests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
def before_all(context):
context.ard = pyard.init("3440", data_dir="/tmp/py-ard")

# an ard with ping set to True
ping_config = {
"ping": True,
}
context.ard_ping = pyard.init("3440", data_dir="/tmp/py-ard", config=ping_config)

# an ard with ARS suffix for lg
lg_ars_config = {
"ARS_as_lg": True,
Expand Down
15 changes: 0 additions & 15 deletions tests/expected-serology.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
{
"redux": [
{
"glstring": "A10",
"ard_type": "G",
"expected_gl": "A*25:01:01G/A*25:01:02/A*25:01:03/A*25:01:04/A*25:01:05/A*25:01:06/A*25:01:07/A*25:01:08/A*25:01:09/A*25:01:10/A*25:01:11/A*25:01:12/A*25:01:14/A*25:01:16/A*25:01:17/A*25:01:19/A*25:02/A*25:03/A*25:04/A*25:05/A*25:06/A*25:08/A*25:09/A*25:10/A*25:11/A*25:13/A*25:14/A*25:15/A*25:16/A*25:17/A*25:18/A*25:19:01/A*25:19:02/A*25:20/A*25:21/A*25:22/A*25:23/A*25:24/A*25:25/A*25:26/A*25:27:01/A*25:27:02/A*25:28/A*25:29/A*25:30/A*25:31/A*25:32/A*25:33/A*25:34/A*25:35/A*25:36/A*25:37/A*25:38/A*25:39/A*25:40/A*25:41/A*25:43/A*25:44/A*25:45/A*25:46/A*25:47/A*25:48/A*25:50/A*25:51/A*25:52/A*25:53/A*25:54/A*25:55/A*25:56/A*25:57/A*25:58/A*25:59/A*25:61/A*25:64/A*25:65/A*25:66/A*25:67/A*25:70/A*25:71/A*25:72/A*25:73/A*26:01:01G/A*26:01:02/A*26:01:03/A*26:01:04/A*26:01:05/A*26:01:06/A*26:01:08/A*26:01:09/A*26:01:10/A*26:01:11/A*26:01:12/A*26:01:13/A*26:01:14/A*26:01:15/A*26:01:16/A*26:01:17/A*26:01:18/A*26:01:19/A*26:01:20/A*26:01:21/A*26:01:22/A*26:01:23/A*26:01:24/A*26:01:26/A*26:01:27/A*26:01:28/A*26:01:29/A*26:01:30/A*26:01:31/A*26:01:33/A*26:01:34/A*26:01:36/A*26:01:37/A*26:01:38/A*26:01:39/A*26:01:41/A*26:01:42/A*26:01:45/A*26:01:48/A*26:01:50/A*26:01:51/A*26:01:52/A*26:01:53/A*26:01:54/A*26:01:57/A*26:01:59/A*26:01:60/A*26:01:61/A*26:01:62/A*26:01:63/A*26:01:64/A*26:01:65/A*26:01:66/A*26:01:69/A*26:02:01/A*26:02:02/A*26:03:01G/A*26:04/A*26:05/A*26:06/A*26:07:01/A*26:07:02/A*26:08:01G/A*26:08:02/A*26:08:03/A*26:09/A*26:10/A*26:12/A*26:13/A*26:14/A*26:15/A*26:16/A*26:17/A*26:18/A*26:19/A*26:20:01/A*26:20:02/A*26:21/A*26:22/A*26:23/A*26:27/A*26:28/A*26:29/A*26:30/A*26:31/A*26:32/A*26:33/A*26:34/A*26:35/A*26:36/A*26:37/A*26:38/A*26:39/A*26:40/A*26:41/A*26:42/A*26:43:01/A*26:43:02/A*26:45/A*26:46/A*26:47/A*26:48/A*26:49/A*26:50/A*26:51/A*26:52/A*26:53/A*26:54/A*26:55/A*26:57/A*26:58/A*26:59/A*26:61/A*26:62/A*26:63/A*26:64/A*26:65/A*26:66/A*26:67/A*26:68/A*26:69/A*26:70/A*26:72/A*26:73/A*26:74/A*26:75/A*26:76/A*26:77/A*26:78/A*26:79/A*26:80/A*26:81/A*26:83/A*26:84/A*26:85/A*26:86/A*26:87/A*26:88/A*26:89/A*26:90/A*26:91/A*26:92/A*26:93/A*26:94/A*26:95/A*26:96/A*26:97/A*26:100/A*26:101/A*26:102/A*26:103/A*26:104/A*26:105/A*26:106/A*26:108/A*26:109/A*26:110/A*26:111/A*26:112/A*26:113/A*26:114/A*26:115/A*26:116/A*26:118/A*26:119/A*26:120/A*26:121/A*26:122/A*26:123/A*26:124/A*26:125/A*26:126/A*26:128/A*26:129/A*26:130/A*26:131/A*26:132/A*26:133/A*26:134/A*26:135/A*26:136/A*26:137/A*26:138/A*26:139/A*26:140/A*26:141/A*26:142/A*26:143/A*26:144/A*26:146/A*26:147/A*26:148/A*26:149/A*26:150/A*26:151/A*26:152/A*26:153/A*26:154/A*26:155/A*26:156/A*26:158/A*26:159/A*26:165/A*26:169/A*26:170/A*26:171/A*26:172/A*26:173/A*26:174/A*26:175/A*26:176/A*26:177/A*26:178/A*26:181/A*26:182/A*26:184/A*26:188/A*26:189/A*26:190/A*26:192/A*26:193/A*26:194/A*26:195/A*26:196/A*26:197/A*26:198/A*26:200/A*26:204:01G/A*26:205/A*26:207/A*26:211/A*26:212/A*26:213/A*26:214/A*34:01:01G/A*34:01:02/A*34:01:03/A*34:01:05/A*34:02:01G/A*34:02:02/A*34:02:03/A*34:02:04/A*34:02:05/A*34:03/A*34:04/A*34:05/A*34:06/A*34:07/A*34:08/A*34:09/A*34:11/A*34:12/A*34:13/A*34:14/A*34:15/A*34:16/A*34:17/A*34:19/A*34:20/A*34:21/A*34:22/A*34:23/A*34:24/A*34:25/A*66:01:01G/A*66:01:02/A*66:01:03/A*66:01:04/A*66:01:05/A*66:02:01G/A*66:03:01G/A*66:04/A*66:05/A*66:06/A*66:07/A*66:09/A*66:10/A*66:11/A*66:12/A*66:13/A*66:14/A*66:15/A*66:16/A*66:18/A*66:19/A*66:20/A*66:21/A*66:22/A*66:23/A*66:24/A*66:25/A*66:26Q/A*66:30/A*66:32/A*66:33/A*66:35/A*66:37/A*66:40/A*66:41/A*66:42/A*66:43"
},
{
"glstring": "A10",
"ard_type": "lg",
"expected_gl": "A*25:01g/A*25:02g/A*25:03g/A*25:04g/A*25:05g/A*25:06g/A*25:08g/A*25:09g/A*25:10g/A*25:11g/A*25:13g/A*25:14g/A*25:15g/A*25:16g/A*25:17g/A*25:18g/A*25:19g/A*25:20g/A*25:21g/A*25:22g/A*25:23g/A*25:24g/A*25:25g/A*25:26g/A*25:27g/A*25:28g/A*25:29g/A*25:30g/A*25:31g/A*25:32g/A*25:33g/A*25:34g/A*25:35g/A*25:36g/A*25:37g/A*25:38g/A*25:39g/A*25:40g/A*25:41g/A*25:43g/A*25:44g/A*25:45g/A*25:46g/A*25:47g/A*25:48g/A*25:50g/A*25:51g/A*25:52g/A*25:53g/A*25:54g/A*25:55g/A*25:56g/A*25:57g/A*25:58g/A*25:59g/A*25:61g/A*25:64g/A*25:65g/A*25:66g/A*25:67g/A*25:70g/A*25:71g/A*25:72g/A*25:73g/A*26:01g/A*26:02g/A*26:03g/A*26:04g/A*26:05g/A*26:06g/A*26:07g/A*26:08g/A*26:09g/A*26:10g/A*26:12g/A*26:13g/A*26:14g/A*26:15g/A*26:16g/A*26:17g/A*26:18g/A*26:19g/A*26:20g/A*26:21g/A*26:22g/A*26:23g/A*26:27g/A*26:28g/A*26:29g/A*26:30g/A*26:31g/A*26:32g/A*26:33g/A*26:34g/A*26:35g/A*26:36g/A*26:37g/A*26:38g/A*26:39g/A*26:40g/A*26:41g/A*26:42g/A*26:43g/A*26:45g/A*26:46g/A*26:47g/A*26:48g/A*26:49g/A*26:50g/A*26:51g/A*26:52g/A*26:53g/A*26:54g/A*26:55g/A*26:57g/A*26:58g/A*26:59g/A*26:61g/A*26:62g/A*26:63g/A*26:64g/A*26:65g/A*26:66g/A*26:67g/A*26:68g/A*26:69g/A*26:70g/A*26:72g/A*26:73g/A*26:74g/A*26:75g/A*26:76g/A*26:77g/A*26:78g/A*26:79g/A*26:80g/A*26:81g/A*26:83g/A*26:84g/A*26:85g/A*26:86g/A*26:87g/A*26:88g/A*26:89g/A*26:90g/A*26:91g/A*26:92g/A*26:93g/A*26:94g/A*26:95g/A*26:96g/A*26:97g/A*26:100g/A*26:101g/A*26:102g/A*26:103g/A*26:104g/A*26:105g/A*26:106g/A*26:108g/A*26:109g/A*26:110g/A*26:111g/A*26:112g/A*26:113g/A*26:114g/A*26:115g/A*26:116g/A*26:118g/A*26:119g/A*26:120g/A*26:121g/A*26:122g/A*26:123g/A*26:124g/A*26:125g/A*26:126g/A*26:128g/A*26:129g/A*26:130g/A*26:131g/A*26:132g/A*26:133g/A*26:134g/A*26:135g/A*26:136g/A*26:137g/A*26:138g/A*26:139g/A*26:140g/A*26:141g/A*26:142g/A*26:143g/A*26:144g/A*26:146g/A*26:147g/A*26:148g/A*26:149g/A*26:150g/A*26:151g/A*26:152g/A*26:153g/A*26:154g/A*26:155g/A*26:156g/A*26:158g/A*26:159g/A*26:165g/A*26:169g/A*26:170g/A*26:171g/A*26:172g/A*26:173g/A*26:174g/A*26:175g/A*26:176g/A*26:177g/A*26:178g/A*26:181g/A*26:182g/A*26:184g/A*26:188g/A*26:189g/A*26:190g/A*26:192g/A*26:193g/A*26:194g/A*26:195g/A*26:196g/A*26:197g/A*26:198g/A*26:200g/A*26:204g/A*26:205g/A*26:207g/A*26:211g/A*26:212g/A*26:213g/A*26:214g/A*34:01g/A*34:02g/A*34:03g/A*34:04g/A*34:05g/A*34:06g/A*34:07g/A*34:08g/A*34:09g/A*34:11g/A*34:12g/A*34:13g/A*34:14g/A*34:15g/A*34:16g/A*34:17g/A*34:19g/A*34:20g/A*34:21g/A*34:22g/A*34:23g/A*34:24g/A*34:25g/A*66:01g/A*66:02g/A*66:03g/A*66:04g/A*66:05g/A*66:06g/A*66:07g/A*66:09g/A*66:10g/A*66:11g/A*66:12g/A*66:13g/A*66:14g/A*66:15g/A*66:16g/A*66:18g/A*66:19g/A*66:20g/A*66:21g/A*66:22g/A*66:23g/A*66:24g/A*66:25g/A*66:26Qg/A*66:30g/A*66:32g/A*66:33g/A*66:35g/A*66:37g/A*66:40g/A*66:41g/A*66:42g/A*66:43g"
},
{
"glstring": "A10",
"ard_type": "lgx",
"expected_gl": "A*25:01/A*25:02/A*25:03/A*25:04/A*25:05/A*25:06/A*25:08/A*25:09/A*25:10/A*25:11/A*25:13/A*25:14/A*25:15/A*25:16/A*25:17/A*25:18/A*25:19/A*25:20/A*25:21/A*25:22/A*25:23/A*25:24/A*25:25/A*25:26/A*25:27/A*25:28/A*25:29/A*25:30/A*25:31/A*25:32/A*25:33/A*25:34/A*25:35/A*25:36/A*25:37/A*25:38/A*25:39/A*25:40/A*25:41/A*25:43/A*25:44/A*25:45/A*25:46/A*25:47/A*25:48/A*25:50/A*25:51/A*25:52/A*25:53/A*25:54/A*25:55/A*25:56/A*25:57/A*25:58/A*25:59/A*25:61/A*25:64/A*25:65/A*25:66/A*25:67/A*25:70/A*25:71/A*25:72/A*25:73/A*26:01/A*26:02/A*26:03/A*26:04/A*26:05/A*26:06/A*26:07/A*26:08/A*26:09/A*26:10/A*26:12/A*26:13/A*26:14/A*26:15/A*26:16/A*26:17/A*26:18/A*26:19/A*26:20/A*26:21/A*26:22/A*26:23/A*26:27/A*26:28/A*26:29/A*26:30/A*26:31/A*26:32/A*26:33/A*26:34/A*26:35/A*26:36/A*26:37/A*26:38/A*26:39/A*26:40/A*26:41/A*26:42/A*26:43/A*26:45/A*26:46/A*26:47/A*26:48/A*26:49/A*26:50/A*26:51/A*26:52/A*26:53/A*26:54/A*26:55/A*26:57/A*26:58/A*26:59/A*26:61/A*26:62/A*26:63/A*26:64/A*26:65/A*26:66/A*26:67/A*26:68/A*26:69/A*26:70/A*26:72/A*26:73/A*26:74/A*26:75/A*26:76/A*26:77/A*26:78/A*26:79/A*26:80/A*26:81/A*26:83/A*26:84/A*26:85/A*26:86/A*26:87/A*26:88/A*26:89/A*26:90/A*26:91/A*26:92/A*26:93/A*26:94/A*26:95/A*26:96/A*26:97/A*26:100/A*26:101/A*26:102/A*26:103/A*26:104/A*26:105/A*26:106/A*26:108/A*26:109/A*26:110/A*26:111/A*26:112/A*26:113/A*26:114/A*26:115/A*26:116/A*26:118/A*26:119/A*26:120/A*26:121/A*26:122/A*26:123/A*26:124/A*26:125/A*26:126/A*26:128/A*26:129/A*26:130/A*26:131/A*26:132/A*26:133/A*26:134/A*26:135/A*26:136/A*26:137/A*26:138/A*26:139/A*26:140/A*26:141/A*26:142/A*26:143/A*26:144/A*26:146/A*26:147/A*26:148/A*26:149/A*26:150/A*26:151/A*26:152/A*26:153/A*26:154/A*26:155/A*26:156/A*26:158/A*26:159/A*26:165/A*26:169/A*26:170/A*26:171/A*26:172/A*26:173/A*26:174/A*26:175/A*26:176/A*26:177/A*26:178/A*26:181/A*26:182/A*26:184/A*26:188/A*26:189/A*26:190/A*26:192/A*26:193/A*26:194/A*26:195/A*26:196/A*26:197/A*26:198/A*26:200/A*26:204/A*26:205/A*26:207/A*26:211/A*26:212/A*26:213/A*26:214/A*34:01/A*34:02/A*34:03/A*34:04/A*34:05/A*34:06/A*34:07/A*34:08/A*34:09/A*34:11/A*34:12/A*34:13/A*34:14/A*34:15/A*34:16/A*34:17/A*34:19/A*34:20/A*34:21/A*34:22/A*34:23/A*34:24/A*34:25/A*66:01/A*66:02/A*66:03/A*66:04/A*66:05/A*66:06/A*66:07/A*66:09/A*66:10/A*66:11/A*66:12/A*66:13/A*66:14/A*66:15/A*66:16/A*66:18/A*66:19/A*66:20/A*66:21/A*66:22/A*66:23/A*66:24/A*66:25/A*66:26Q/A*66:30/A*66:32/A*66:33/A*66:35/A*66:37/A*66:40/A*66:41/A*66:42/A*66:43"
},
{
"glstring": "A19",
"ard_type": "G",
Expand Down
2 changes: 1 addition & 1 deletion tests/features/allele.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feature: Alleles
| C*02:02 | lgx | C*02:02 |
| C*02:10 | lg | C*02:02g |
| C*02:10 | lgx | C*02:02 |
| C*06:17 | lgx | C*06:17 |
| C*06:17 | lgx | C*06:02 |


Scenario Outline: allele reduction with ARS suffix
Expand Down
3 changes: 3 additions & 0 deletions tests/features/p_g_group.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Feature: P and G Groups


Scenario Outline: allele reduction with ping
`ping` is the default.

If there is no G group for the allele, it should use the P group allele.

Given the allele as <Allele>
When reducing on the <Level> level with ping
Expand Down
Loading

0 comments on commit 87eece1

Please sign in to comment.