Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpsd-software-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MPSD Computational Science
mpsd-software-manager
Commits
09d9f633
Commit
09d9f633
authored
1 year ago
by
Hans Fangohr
Browse files
Options
Downloads
Patches
Plain Diff
refactor: we may need this function to create a git repo again.
parent
06b3abd4
No related branches found
No related tags found
2 merge requests
!19
Move linux-debian11 into main
,
!9
force `subprocess.run` to check return code is 0
Pipeline
#368347
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests.py
+30
-12
30 additions, 12 deletions
tests.py
with
30 additions
and
12 deletions
tests.py
+
30
−
12
View file @
09d9f633
...
@@ -9,6 +9,35 @@ import pytest
...
@@ -9,6 +9,35 @@ import pytest
mod
=
importlib
.
import_module
(
"
mpsd-software-environment
"
)
mod
=
importlib
.
import_module
(
"
mpsd-software-environment
"
)
def
create_mock_git_repository
(
target_directory
,
create_directory
=
True
):
"""
Create a git repository in the directory `target_directory`.
Arguments
---------
target_directory : pathlib.Path
- path at which the root of the repository should be located (i.e. `.git` folder)
create_directory : bool
- create `target_directory` and parent directories if True
"""
# create directory first
if
create_directory
:
target_directory
.
mkdir
(
parents
=
True
)
# then create git repository:
with
mod
.
os_chdir
(
str
(
target_directory
)):
subprocess
.
run
(
"
git init .
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
echo
'
fake content
'
> readme.txt
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
git add readme.txt
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
pwd
"
,
shell
=
True
)
subprocess
.
run
(
'
git commit -m
"
first commit
"
readme.txt
'
,
shell
=
True
,
check
=
True
)
def
test_os_chdir
(
tmp_path
):
def
test_os_chdir
(
tmp_path
):
# create a temporary directory for testing
# create a temporary directory for testing
temp_dir
=
tmp_path
/
"
test_os_chdir
"
temp_dir
=
tmp_path
/
"
test_os_chdir
"
...
@@ -43,18 +72,7 @@ def test_prepare_environment(tmp_path):
...
@@ -43,18 +72,7 @@ def test_prepare_environment(tmp_path):
# log that information. For this to work, we need to execute the command
# log that information. For this to work, we need to execute the command
# within a directory tree that has a git repository at the same or high
# within a directory tree that has a git repository at the same or high
# level. Let's create one:
# level. Let's create one:
create_mock_git_repository
(
script_dir
)
# create directory first
script_dir
.
mkdir
(
parents
=
True
)
# then create git repository:
with
mod
.
os_chdir
(
str
(
script_dir
)):
subprocess
.
run
(
"
git init .
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
echo
'
fake content
'
> readme.txt
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
git add readme.txt
"
,
shell
=
True
,
check
=
True
)
subprocess
.
run
(
"
pwd
"
,
shell
=
True
)
subprocess
.
run
(
'
git commit -m
"
first commit
"
readme.txt
'
,
shell
=
True
,
check
=
True
)
# now call the function we want to test
# now call the function we want to test
result
=
mod
.
prepare_environment
(
result
=
mod
.
prepare_environment
(
...
...
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