Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
concepts-processing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
meldb
concepts-processing
Commits
767dfd1c
Commit
767dfd1c
authored
4 months ago
by
mjbonifa
Browse files
Options
Downloads
Patches
Plain Diff
added initial pytests for basic workflow
parent
28aecd75
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
phen.py
+8
-2
8 additions, 2 deletions
phen.py
tests/test_acmc.py
+92
-0
92 additions, 0 deletions
tests/test_acmc.py
tests/test_commands.py
+0
-75
0 additions, 75 deletions
tests/test_commands.py
with
100 additions
and
77 deletions
phen.py
+
8
−
2
View file @
767dfd1c
...
@@ -182,7 +182,7 @@ def init(phen_dir, remote_url):
...
@@ -182,7 +182,7 @@ def init(phen_dir, remote_url):
repo
.
git
.
add
(
all
=
True
)
repo
.
git
.
add
(
all
=
True
)
repo
.
index
.
commit
(
"
initialised the phen git repo.
"
)
repo
.
index
.
commit
(
"
initialised the phen git repo.
"
)
print
(
f
"
Phenotype initialised
"
)
print
(
f
"
Phenotype initialised
successfully
"
)
def
validate
(
phen_dir
):
def
validate
(
phen_dir
):
"""
Validates the phenotype directory is a git repo with standard structure
"""
"""
Validates the phenotype directory is a git repo with standard structure
"""
...
@@ -566,7 +566,7 @@ def map(phen_dir, target_code_type, translate=True, verify=True):
...
@@ -566,7 +566,7 @@ def map(phen_dir, target_code_type, translate=True, verify=True):
print
(
f
"
Saved concept_sets to
{
str
(
concept_set_path
.
resolve
())
}
"
)
print
(
f
"
Saved concept_sets to
{
str
(
concept_set_path
.
resolve
())
}
"
)
print
(
f
"
Phenotype process
ing completed
"
)
print
(
f
"
Phenotype process
ed successfully
"
)
def
publish
(
phen_dir
):
def
publish
(
phen_dir
):
"""
Publishes updates to the phenotype by commiting all changes to the repo directory
"""
"""
Publishes updates to the phenotype by commiting all changes to the repo directory
"""
...
@@ -626,6 +626,8 @@ def publish(phen_dir):
...
@@ -626,6 +626,8 @@ def publish(phen_dir):
except
AttributeError
:
except
AttributeError
:
print
(
"
No remote named
'
origin
'
found, local repo.
"
)
print
(
"
No remote named
'
origin
'
found, local repo.
"
)
print
(
f
"
Phenotype published successfully
"
)
def
copy
(
phen_dir
,
target_dir
,
version
=
None
):
def
copy
(
phen_dir
,
target_dir
,
version
=
None
):
"""
Copys a phen repo at a specific tagged version into a target directory
"""
"""
Copys a phen repo at a specific tagged version into a target directory
"""
...
@@ -666,6 +668,8 @@ def copy(phen_dir, target_dir, version=None):
...
@@ -666,6 +668,8 @@ def copy(phen_dir, target_dir, version=None):
print
(
f
"
Copied
{
phen_path
}
{
repo
.
head
.
commit
.
hexsha
[
:
7
]
}
in
{
copy_path
}
"
)
print
(
f
"
Copied
{
phen_path
}
{
repo
.
head
.
commit
.
hexsha
[
:
7
]
}
in
{
copy_path
}
"
)
print
(
f
"
Phenotype copied successfully
"
)
def
diff
(
phen_dir
,
phen_old_dir
):
def
diff
(
phen_dir
,
phen_old_dir
):
"""
Compare the differences between two versions of a phenotype
"""
"""
Compare the differences between two versions of a phenotype
"""
...
@@ -738,6 +742,8 @@ def diff(phen_dir, phen_old_dir):
...
@@ -738,6 +742,8 @@ def diff(phen_dir, phen_old_dir):
report
.
write
(
f
"
- Changed concepts []
\n\n
"
)
report
.
write
(
f
"
- Changed concepts []
\n\n
"
)
print
(
f
"
Phenotypes diff
'
d successfully
"
)
# Here's the atlas code that needs to go into anotehr function
# Here's the atlas code that needs to go into anotehr function
# if output_path == "atlas":
# if output_path == "atlas":
# vocab_id = summary_config["omop"]["vocabulary_id"]
# vocab_id = summary_config["omop"]["vocabulary_id"]
...
...
This diff is collapsed.
Click to expand it.
tests/test_acmc.py
0 → 100644
+
92
−
0
View file @
767dfd1c
import
pytest
import
argparse
import
sys
import
shutil
import
trud
import
omop
import
phen
import
acmc
from
pathlib
import
Path
@pytest.fixture
def
tmp_dir
():
# Setup tmp directory
temp_dir
=
Path
(
"
./tests/tmp
"
)
temp_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# Yield the directory path to the test function
yield
temp_dir
# Remove the directory after the test finishes
shutil
.
rmtree
(
temp_dir
)
def
test_phen_init_local_default
(
tmp_dir
,
monkeypatch
,
capsys
):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
init
"
])
# Mock input() to return "yes" to the question about reinitialising the directory
monkeypatch
.
setattr
(
"
builtins.input
"
,
lambda
_
:
"
y
"
)
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype initialised successfully
"
in
captured
.
out
def
test_phen_init_local_specified
(
tmp_dir
,
monkeypatch
,
capsys
):
phen_path
=
tmp_dir
/
"
phen
"
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
init
"
,
"
-d
"
,
str
(
phen_path
.
resolve
())])
# Mock input() to return "yes" to the question about reinitialising the directory
monkeypatch
.
setattr
(
"
builtins.input
"
,
lambda
_
:
"
y
"
)
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype initialised successfully
"
in
captured
.
out
def
test_phen_workflow
(
tmp_dir
,
monkeypatch
,
capsys
):
phen_path
=
tmp_dir
/
"
phen
"
phen_path
=
phen_path
.
resolve
()
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
init
"
,
"
-d
"
,
str
(
phen_path
.
resolve
())])
# Mock input() to return "yes" to the question about reinitialising the directory
monkeypatch
.
setattr
(
"
builtins.input
"
,
lambda
_
:
"
y
"
)
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype initialised successfully
"
in
captured
.
out
# copy examples across
shutil
.
rmtree
(
phen_path
/
'
codes
'
)
ex_path
=
Path
(
'
./examples
'
).
resolve
()
for
item
in
ex_path
.
iterdir
():
source
=
ex_path
/
item
.
name
destination
=
phen_path
/
item
.
name
if
source
.
is_dir
():
shutil
.
copytree
(
source
,
destination
)
else
:
shutil
.
copy2
(
source
,
destination
)
shutil
.
copy
(
phen_path
/
'
config1.json
'
,
phen_path
/
'
config.json
'
)
# validate phenotype
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
validate
"
,
"
-d
"
,
str
(
phen_path
.
resolve
())])
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype validated successfully
"
in
captured
.
out
# map phenotype
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
map
"
,
"
-d
"
,
str
(
phen_path
.
resolve
()),
"
-t
"
,
"
read2
"
,
"
-tr
"
,
"
-ve
"
])
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype processed successfully
"
in
captured
.
out
# publish phenotype
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
publish
"
,
"
-d
"
,
str
(
phen_path
.
resolve
())])
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype published successfully
"
in
captured
.
out
# copy phenotype'
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
copy
"
,
"
-d
"
,
str
(
phen_path
.
resolve
()),
"
-td
"
,
str
(
tmp_dir
.
resolve
()),
"
-v
"
,
"
v1.0.3
"
])
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotype copied successfully
"
in
captured
.
out
# diff phenotype
old_path
=
tmp_dir
/
"
v1.0.3
"
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
acmc.py
"
,
"
phen
"
,
"
diff
"
,
"
-d
"
,
str
(
phen_path
.
resolve
()),
"
-old
"
,
str
(
old_path
.
resolve
())])
acmc
.
main
()
captured
=
capsys
.
readouterr
()
assert
"
Phenotypes diff
'
d successfully
"
in
captured
.
out
This diff is collapsed.
Click to expand it.
tests/test_commands.py
deleted
100644 → 0
+
0
−
75
View file @
28aecd75
import
pytest
import
argparse
from
unittest.mock
import
patch
,
MagicMock
import
trud
import
omop
import
phen
from
pathlib
import
Path
from
acmc
import
trud_install
,
omop_install
,
omop_clear
,
omop_delete
,
phen_init
,
phen_validate
,
phen_map
,
phen_publish
,
phen_copy
,
phen_diff
def
test_trud_install
():
with
patch
(
"
trud.install
"
)
as
mock_install
:
args
=
argparse
.
Namespace
(
api_key
=
"
test_key
"
)
trud_install
(
args
)
mock_install
.
assert_called_once_with
(
"
test_key
"
)
def
test_omop_install
():
with
patch
(
"
omop.install
"
)
as
mock_install
:
args
=
argparse
.
Namespace
(
omop_folder
=
"
/path/to/omop
"
)
omop_install
(
args
)
mock_install
.
assert_called_once_with
(
omop
.
OMOP_DB_PATH
,
"
/path/to/omop
"
)
def
test_omop_clear
():
with
patch
(
"
omop.clear
"
)
as
mock_clear
:
args
=
argparse
.
Namespace
()
omop_clear
(
args
)
mock_clear
.
assert_called_once_with
(
omop
.
OMOP_DB_PATH
)
def
test_omop_delete
():
with
patch
(
"
omop.delete
"
)
as
mock_delete
:
args
=
argparse
.
Namespace
()
omop_delete
(
args
)
mock_delete
.
assert_called_once_with
(
omop
.
OMOP_DB_PATH
)
def
test_phen_init
():
with
patch
(
"
phen.init
"
)
as
mock_init
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
)
phen_init
(
args
)
mock_init
.
assert_called_once_with
(
"
/path/to/phen
"
)
def
test_phen_validate
():
with
patch
(
"
phen.validate
"
)
as
mock_validate
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
)
phen_validate
(
args
)
mock_validate
.
assert_called_once_with
(
"
/path/to/phen
"
)
def
test_phen_map
():
with
patch
(
"
phen.map
"
)
as
mock_map
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
,
target_coding
=
"
icd10_code
"
,
translate
=
True
,
verify
=
True
)
phen_map
(
args
)
mock_map
.
assert_called_once_with
(
"
/path/to/phen
"
,
"
icd10_code
"
,
True
,
True
)
def
test_phen_publish
():
with
patch
(
"
phen.publish
"
)
as
mock_publish
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
)
phen_publish
(
args
)
mock_publish
.
assert_called_once_with
(
"
/path/to/phen
"
)
def
test_phen_copy
():
with
patch
(
"
phen.copy
"
)
as
mock_copy
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
,
target_dir
=
"
/path/to/target
"
,
version
=
"
1.0
"
)
phen_copy
(
args
)
mock_copy
.
assert_called_once_with
(
"
/path/to/phen
"
,
"
/path/to/target
"
,
"
1.0
"
)
def
test_phen_diff
():
with
patch
(
"
phen.diff
"
)
as
mock_diff
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
,
phen_dir_old
=
"
/path/to/old_phen
"
)
phen_diff
(
args
)
mock_diff
.
assert_called_once_with
(
"
/path/to/phen
"
,
"
/path/to/old_phen
"
)
def
test_phen_local
():
with
patch
(
"
phen.diff
"
)
as
mock_diff
:
args
=
argparse
.
Namespace
(
phen_dir
=
"
/path/to/phen
"
,
phen_dir_old
=
"
/path/to/old_phen
"
)
phen_diff
(
args
)
mock_diff
.
assert_called_once_with
(
"
/path/to/phen
"
,
"
/path/to/old_phen
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment