Commit 684fbe26 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

ENH: add test for cdash_handler

No related merge requests found
Showing with 136 additions and 88 deletions
+136 -88
...@@ -24,7 +24,8 @@ import glob ...@@ -24,7 +24,8 @@ import glob
import re import re
import unittest import unittest
trace = True
trace = False
class Handler: class Handler:
# project # project
...@@ -64,9 +65,9 @@ class Handler: ...@@ -64,9 +65,9 @@ class Handler:
configure_file.close() configure_file.close()
print( content ) print( content )
self.configure_path = configure_xml self.configure_path = configure_xml
return True return self.configure_path
print("Could not find the Configure.xml produced by ctest") print("Could not find the Configure.xml produced by ctest")
return False return
def GetSite (self , build_dir="" ): def GetSite (self , build_dir="" ):
""" """
...@@ -76,7 +77,7 @@ class Handler: ...@@ -76,7 +77,7 @@ class Handler:
build_dir = self.build_dir build_dir = self.build_dir
if self.configure_path == "" and not self.GetConfigureFile( build_dir ): if self.configure_path == "" and not self.GetConfigureFile( build_dir ):
print ("Error in GetSite function, could not find Configure.xml") print ("Error in GetSite function, could not find Configure.xml")
return False return
configure_file = open( self.configure_path, "r" ) configure_file = open( self.configure_path, "r" )
content = configure_file.read() content = configure_file.read()
configure_file.close() configure_file.close()
...@@ -89,9 +90,9 @@ class Handler: ...@@ -89,9 +90,9 @@ class Handler:
if trace: if trace:
print("site value \n" , site.group(1)) print("site value \n" , site.group(1))
self.site = site.group(1) self.site = site.group(1)
return True return self.site
print("Could not retreive site value") print("Could not retreive site value")
return False return
return return
def GetName (self , build_dir = ""): def GetName (self , build_dir = ""):
...@@ -103,7 +104,7 @@ class Handler: ...@@ -103,7 +104,7 @@ class Handler:
build_dir = self.build_dir build_dir = self.build_dir
if self.configure_path == "" and not self.GetConfigureFile( build_dir ): if self.configure_path == "" and not self.GetConfigureFile( build_dir ):
print ("Error in GetName function, could not find Configure.xml") print ("Error in GetName function, could not find Configure.xml")
return False return
configure_file = open( self.configure_path, "r" ) configure_file = open( self.configure_path, "r" )
content = configure_file.read() content = configure_file.read()
configure_file.close() configure_file.close()
...@@ -116,9 +117,9 @@ class Handler: ...@@ -116,9 +117,9 @@ class Handler:
if trace: if trace:
print("name value \n" , name.group(1)) print("name value \n" , name.group(1))
self.name = name.group(1) self.name = name.group(1)
return True return self.name
print("Could not retreive name value") print("Could not retreive name value")
return False return
def GetStamp (self , build_dir = "" ): def GetStamp (self , build_dir = "" ):
""" """
...@@ -128,7 +129,7 @@ class Handler: ...@@ -128,7 +129,7 @@ class Handler:
build_dir = self.build_dir build_dir = self.build_dir
if self.configure_path == "" and not self.GetConfigureFile( build_dir ): if self.configure_path == "" and not self.GetConfigureFile( build_dir ):
print ("Error in GetStamp function, could not find Configure.xml") print ("Error in GetStamp function, could not find Configure.xml")
return False return
configure_file = open( self.configure_path, "r" ) configure_file = open( self.configure_path, "r" )
content = configure_file.read() content = configure_file.read()
stamp_regex = re.compile( "\\bBuildStamp\\b=\"([0-9,\\s,\(,\),\-,\.,_,A-Z,a-z]+)\"") stamp_regex = re.compile( "\\bBuildStamp\\b=\"([0-9,\\s,\(,\),\-,\.,_,A-Z,a-z]+)\"")
...@@ -140,30 +141,33 @@ class Handler: ...@@ -140,30 +141,33 @@ class Handler:
if trace: if trace:
print("Stamp value \n" , stamp.group(1)) print("Stamp value \n" , stamp.group(1))
self.stamp = stamp.group(1) self.stamp = stamp.group(1)
return True return self.stamp
print("Could not retreive stamp value") print("Could not retreive stamp value")
return False return
def GetBuildId (self, **kwargs): def GetBuildId (self, **kwargs):
""" """
This function is returning the buildid. Dict can be passed with the This function is returning the buildid. Dict can be passed with the
different informations different informations
""" """
trace = True
site = self.site site = self.site
stamp = self.stamp stamp = self.stamp
name = self.name name = self.name
project = self.project project = self.project
print( kwargs.items() )
for key , value in kwargs.items(): for key , value in kwargs.items():
if key == "site": if key == "site":
site = value site = value
if key == "stamp": if key == "stamp":
stamp == value stamp = value
if key == "name": if key == "name":
name = value name = value
if key == "project": if key == "project":
project = value project = value
if ( site == "" or stamp == "" or name == "" or project == ""): if ( site == "" or stamp == "" or name == "" or project == ""):
print( "Not enougth argument given for buildid request ") print( "Not enougth argument given for buildid request \
site:"+site+", stamp:"+stamp+", name:"+name+", project:"+project+".")
# TODO # TODO
return return
buildid_url = self.url + "/api/v1/getbuildid.php?" buildid_url = self.url + "/api/v1/getbuildid.php?"
...@@ -172,13 +176,15 @@ class Handler: ...@@ -172,13 +176,15 @@ class Handler:
buildid_url += "stamp=" + stamp + "&" buildid_url += "stamp=" + stamp + "&"
buildid_url += "name=" + name buildid_url += "name=" + name
build_id_page = requests.get(buildid_url) build_id_page = requests.get(buildid_url)
print ( build_id_page.text ) if trace:
print ( build_id_page.text )
build_id_regex = re.compile( "<buildid>([0-9]+)</buildid>" ) build_id_regex = re.compile( "<buildid>([0-9]+)</buildid>" )
buildid = build_id_regex.search( build_id_page.text ) buildid = build_id_regex.search( build_id_page.text )
if buildid: if buildid:
self.buildid = buildid.group(1) self.buildid = buildid.group(1)
print ( "build id is ", self.buildid) if trace:
return True print ( "build id is ", self.buildid)
return buildid.group(1)
else: else:
print("Error in recovering buildid") print("Error in recovering buildid")
return False return False
...@@ -192,39 +198,41 @@ class Handler: ...@@ -192,39 +198,41 @@ class Handler:
buildid = self.buildid buildid = self.buildid
if ( buildid == "" ): if ( buildid == "" ):
print( "Not enougth argument given to build url") print( "Not enougth argument given to build url")
# TODO
return return
build_url = self.url build_url = self.url
build_url +="/buildSummary.php?" build_url +="/buildSummary.php?"
build_url += "buildid=" + self.buildid build_url += "buildid=" + buildid
return build_url return build_url
#TODO
# class TestHandler(unittest.TestCase):
# def test_GetConfigureFile (self):
# def test_GetName (self):
# def test_GetStamp (self):
# def test_GetBuildId (self):
# def test_GetBuildUrl (self):
""" """
TODO : TODO :
documentation, header, test if it is possible. documentation, header, test if it is possible.
the script aims only at recovering the build url the script aims only at recovering the build url
""" """
# The script needs the project name.
if __name__ == "__main__": if __name__ == "__main__":
handler = Handler() if ( len(sys.argv) < 5 ):
handler.build_dir = "" print("Usage : "+sys.argv[0]+" commit_sha1 project_id build_directory token")
handler.GetStamp() if trace:
print (handler.stamp) print (sys.argv)
handler = cdash_handler.Handler()
build_dir = os.path.join( sys.argv[3] , "build/")
if trace:
print("build_dir is: " + build_dir)
handler.build_dir = build_dir
handler.GetSite() handler.GetSite()
print (handler.site)
handler.GetName() handler.GetName()
print (handler.name) handler.GetStamp()
\ No newline at end of file handler.GetBuildId()
cdash_url = handler.GetBuildUrl()
if trace:
print ( "cdash_url is: " + cdash_url )
gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
gitlab_url += sys.argv[2] + "/statuses/" + sys.argv[1]
params = {'name':'cdash:' + handler.site , 'state': 'success' ,\
'target_url' : cdash_url}
headers = {'PRIVATE-TOKEN' : sys.argv[4] }
gitlab_request=requests.post(gitlab_url, headers = headers, params = params)
if trace:
print ("gitlab_request.url: " + gitlab_request.url)
print ("gitlab_request.text: " + gitlab_request.text)
#
# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import cdash_handler
import requests
import os.path
import sys
if __name__ == "__main__":
if ( len(sys.argv) < 5 ):
print("Usage : "+sys.argv[0]+" commit_sha1 project_id build_directory token")
print (sys.argv)
handler = cdash_handler.Handler()
build_dir = os.path.join( sys.argv[3] , "build/")
print("build_dir is ", build_dir)
handler.build_dir = build_dir
handler.GetSite()
handler.GetName()
handler.GetStamp()
handler.GetBuildId()
cdash_url = handler.GetBuildUrl()
print ( cdash_url )
gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
gitlab_url += sys.argv[2] + "/statuses/" + sys.argv[1]
params = {'name':'cdash:' + handler.site , 'state': 'success' ,\
'target_url' : cdash_url}
print (handler.name)
headers = {'PRIVATE-TOKEN' : sys.argv[4] }
gitlab_request=requests.post(gitlab_url, headers = headers, params = params)
print (gitlab_request.url)
print (gitlab_request.text)
\ No newline at end of file
This folder aims at simulating a build directory. It contains the sub-durectory Testing with a Configure.xml file as the one generated by ctest.
<?xml version="1.0" encoding="UTF-8"?>
<Site BuildName="185_f-54sf_ghs-dgh (out_space)"
BuildStamp="20190320-1706-Experimental_test"
Name="debian-unstable-gcc.42"
Generator="ctest-3.13.4"
CompilerName=""
CompilerVersion=""
OSName="Linux"
Hostname="0e82a8db0490"
OSRelease="4.13.0-43-generic"
OSVersion="#48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018"
OSPlatform="x86_64"
Is64Bits="1"
VendorString="GenuineIntel"
VendorID="Intel Corporation"
FamilyID="6"
ModelID="78"
ProcessorCacheSize="3072"
NumberOfLogicalCPU="4"
NumberOfPhysicalCPU="2"
TotalVirtualMemory="5720"
TotalPhysicalMemory="7858"
LogicalProcessorsPerPhysical="2"
ProcessorClockFrequency="1626.81"
>
<Configure>
<StartDateTime>Mar 20 17:06 UTC</StartDateTime>
<StartConfigureTime>1553101581</StartConfigureTime>
<ConfigureCommand>--</ConfigureCommand>
<Log>--</Log>
<ConfigureStatus>0</ConfigureStatus>
<EndDateTime>Mar 20 17:06 UTC</EndDateTime>
<EndConfigureTime>1553101601</EndConfigureTime>
<ElapsedMinutes>0</ElapsedMinutes>
</Configure>
</Site>
import unittest
import os.path
import sys
# This is done so we can access the module handler
synthetic_build_dir = os.path.dirname(os.path.realpath(__file__))
(module_path , _) = os.path.split(synthetic_build_dir)
sys.path.append(module_path)
import cdash_handler
class TestHandler(unittest.TestCase):
def test_GetConfigureFile (self):
handler = cdash_handler.Handler()
handler.build_dir = synthetic_build_dir
config_path = handler.GetConfigureFile()
self.assertTrue(os.path.exists(config_path))
def test_GetName (self):
handler = cdash_handler.Handler()
handler.build_dir = synthetic_build_dir
name = handler.GetName()
self.assertTrue("185_f-54sf_ghs-dgh (out_space)" == name)
def test_GetSite (self):
handler = cdash_handler.Handler()
handler.build_dir = synthetic_build_dir
site = handler.GetSite()
self.assertTrue("debian-unstable-gcc.42" == site)
def test_GetStamp (self):
handler = cdash_handler.Handler()
handler.build_dir = synthetic_build_dir
stamp = handler.GetStamp()
self.assertTrue("20190320-1706-Experimental_test" == stamp)
def test_GetBuildId (self):
handler = cdash_handler.Handler()
buildid= handler.GetBuildId( site="debian-unstable-gcc" ,\
stamp="20190319-1243-Experimental" , name="0388a356 (debian_CI)")
self.assertTrue( "1" == buildid )
def test_GetBuildUrl (self):
handler = cdash_handler.Handler()
url = handler.GetBuildUrl("1")
self.assertTrue( \
"https://cdash.orfeo-toolbox.org/buildSummary.php?buildid=1" == url)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment