Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
LOFAR2.0
tango
Commits
c968f2f6
Commit
c968f2f6
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-497
: Added tests for measures
parent
da8e07ab
No related branches found
No related tags found
1 merge request
!204
L2SS-497: Add and manage casacore measures tables
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tangostationcontrol/tangostationcontrol/common/measures.py
+4
-3
4 additions, 3 deletions
tangostationcontrol/tangostationcontrol/common/measures.py
tangostationcontrol/tangostationcontrol/test/common/test_measures.py
+73
-0
73 additions, 0 deletions
...ncontrol/tangostationcontrol/test/common/test_measures.py
with
77 additions
and
3 deletions
tangostationcontrol/tangostationcontrol/common/measures.py
+
4
−
3
View file @
c968f2f6
...
@@ -39,7 +39,7 @@ import sys
...
@@ -39,7 +39,7 @@ import sys
IERS_ROOTDIR
=
"
/opt/IERS
"
IERS_ROOTDIR
=
"
/opt/IERS
"
# Where to download files to
# Where to download files to
TEMP
DIR
=
"
/tmp
"
DOWNLOAD_
DIR
=
"
/tmp
"
# Where new measures can be downloaded
# Where new measures can be downloaded
MEASURES_URL
=
"
ftp://ftp.astron.nl/outgoing/Measures/WSRT_Measures.ztar
"
MEASURES_URL
=
"
ftp://ftp.astron.nl/outgoing/Measures/WSRT_Measures.ztar
"
...
@@ -73,6 +73,7 @@ def use_measures_directory(newdir):
...
@@ -73,6 +73,7 @@ def use_measures_directory(newdir):
# switch to new directory
# switch to new directory
current_symlink
=
pathlib
.
Path
(
IERS_ROOTDIR
,
"
current
"
)
current_symlink
=
pathlib
.
Path
(
IERS_ROOTDIR
,
"
current
"
)
if
current_symlink
.
exists
():
current_symlink
.
unlink
()
current_symlink
.
unlink
()
current_symlink
.
symlink_to
(
newdir
)
current_symlink
.
symlink_to
(
newdir
)
...
@@ -100,7 +101,7 @@ def download_measures() -> str:
...
@@ -100,7 +101,7 @@ def download_measures() -> str:
iers_dir
.
mkdir
()
iers_dir
.
mkdir
()
try
:
try
:
measures_filename
=
pathlib
.
Path
(
TEMP
DIR
,
"
WSRT_Measures.ztar
"
)
measures_filename
=
pathlib
.
Path
(
DOWNLOAD_
DIR
,
"
WSRT_Measures.ztar
"
)
# download measures
# download measures
urllib
.
request
.
urlretrieve
(
MEASURES_URL
,
str
(
measures_filename
))
urllib
.
request
.
urlretrieve
(
MEASURES_URL
,
str
(
measures_filename
))
...
...
This diff is collapsed.
Click to expand it.
tangostationcontrol/tangostationcontrol/test/common/test_measures.py
0 → 100644
+
73
−
0
View file @
c968f2f6
# -*- coding: utf-8 -*-
#
# This file is part of the LOFAR 2.0 Station Software
#
#
#
# Distributed under the terms of the APACHE license.
# See LICENSE.txt for more info.
import
urllib.request
import
os.path
import
datetime
from
unittest
import
mock
import
shutil
import
tempfile
import
time
from
tangostationcontrol.common
import
measures
from
tangostationcontrol.test
import
base
# where our WSRT_Measures.ztar surrogate is located
fake_measures
=
os
.
path
.
dirname
(
__file__
)
+
"
/fake_measures.ztar
"
class
TestMeasures
(
base
.
TestCase
):
@mock.patch.object
(
urllib
.
request
,
'
urlretrieve
'
)
def
test_download_and_use
(
self
,
m_urlretrieve
):
"""
Test downloading and using new measures tables.
"""
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
,
\
mock
.
patch
(
'
tangostationcontrol.common.measures.IERS_ROOTDIR
'
,
tmpdirname
)
as
rootdir
,
\
mock
.
patch
(
'
tangostationcontrol.common.measures.DOWNLOAD_DIR
'
,
tmpdirname
)
as
downloaddir
:
# emulate the download
m_urlretrieve
.
side_effect
=
lambda
*
args
,
**
kw
:
shutil
.
copyfile
(
fake_measures
,
tmpdirname
+
"
/WSRT_Measures.ztar
"
)
# 'download' and process our fake measures
newdir
=
measures
.
download_measures
()
# active them
measures
.
use_measures_directory
(
newdir
)
# check if they're activated
self
.
assertIn
(
newdir
,
measures
.
get_available_measures_directories
())
self
.
assertEqual
(
newdir
,
measures
.
get_measures_directory
())
@mock.patch.object
(
urllib
.
request
,
'
urlretrieve
'
)
def
test_switch_tables
(
self
,
m_urlretrieve
):
"""
Test switching between available sets of measures tables.
"""
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
,
\
mock
.
patch
(
'
tangostationcontrol.common.measures.IERS_ROOTDIR
'
,
tmpdirname
)
as
rootdir
,
\
mock
.
patch
(
'
tangostationcontrol.common.measures.DOWNLOAD_DIR
'
,
tmpdirname
)
as
downloaddir
:
# emulate the download
m_urlretrieve
.
side_effect
=
lambda
*
args
,
**
kw
:
shutil
.
copyfile
(
fake_measures
,
tmpdirname
+
"
/WSRT_Measures.ztar
"
)
# 'download' two measures with different timestamps
newdir1
=
measures
.
download_measures
()
time
.
sleep
(
1
)
newdir2
=
measures
.
download_measures
()
# check if both are available
self
.
assertIn
(
newdir1
,
measures
.
get_available_measures_directories
())
self
.
assertIn
(
newdir2
,
measures
.
get_available_measures_directories
())
# switch between the two
measures
.
use_measures_directory
(
newdir1
)
self
.
assertEqual
(
newdir1
,
measures
.
get_measures_directory
())
measures
.
use_measures_directory
(
newdir2
)
self
.
assertEqual
(
newdir2
,
measures
.
get_measures_directory
())
measures
.
use_measures_directory
(
newdir1
)
self
.
assertEqual
(
newdir1
,
measures
.
get_measures_directory
())
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