Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reference-repository
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
grid5000
reference-repository
Commits
caa7ffe7
Commit
caa7ffe7
authored
5 years ago
by
Lucas Nussbaum
Browse files
Options
Downloads
Patches
Plain Diff
[spec] move helpers to spec_helper
parent
c4599e29
No related branches found
No related tags found
1 merge request
!68
Bug11327 - add optional cores_affinity definition to force cores<->GPU allocation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
spec/oar_properties_spec.rb
+0
-62
0 additions, 62 deletions
spec/oar_properties_spec.rb
spec/spec_helper.rb
+63
-0
63 additions, 0 deletions
spec/spec_helper.rb
with
63 additions
and
62 deletions
spec/oar_properties_spec.rb
+
0
−
62
View file @
caa7ffe7
$LOAD_PATH
.
unshift
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)))
$LOAD_PATH
.
unshift
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)))
require
'spec_helper'
require
'spec_helper'
require
'rspec'
require
'webmock/rspec'
$LOAD_PATH
.
unshift
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'../lib'
)))
require
'refrepo'
require
'refrepo/gen/oar-properties'
STUBDIR
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
WebMock
.
disable_net_connect!
(
allow_localhost:
true
)
conf
=
RefRepo
::
Utils
.
get_api_config
conf
=
RefRepo
::
Utils
.
get_api_config
def
load_stub_file_content
(
stub_filename
)
if
not
File
.
exist?
(
"
#{
STUBDIR
}
/stub_oar_properties/
#{
stub_filename
}
"
)
raise
(
"Cannot find
#{
stub_filename
}
in '
#{
STUBDIR
}
/stub_oar_properties/'"
)
end
return
IO
.
read
(
"
#{
STUBDIR
}
/stub_oar_properties/
#{
stub_filename
}
"
)
end
# This code comes from https://gist.github.com/herrphon/2d2ebbf23c86a10aa955
# and enables to capture all output made on stdout and stderr by a block of code
def
capture
(
&
_block
)
begin
$stdout
=
StringIO
.
new
$stderr
=
StringIO
.
new
yield
result
=
{}
result
[
:stdout
]
=
$stdout
.
string
result
[
:stderr
]
=
$stderr
.
string
ensure
$stdout
=
STDOUT
$stderr
=
STDERR
end
result
end
def
str_block_to_regexp
(
str
)
str1
=
str
.
gsub
(
"|"
,
"
\\\\
|"
)
str2
=
str1
.
gsub
(
"+"
,
"
\\\\
+"
)
return
Regexp
.
new
str2
end
def
prepare_stubs
(
oar_api
,
data_hierarchy
)
conf
=
RefRepo
::
Utils
.
get_api_config
stubbed_addresses
=
[
"
#{
conf
[
"uri"
]
}
"
,
"
#{
conf
[
"uri"
]
}
/oarapi/resources/details.json?limit=999999"
,
"
#{
conf
[
"uri"
]
}
stable/sites/fakesite/internal/oarapi/resources/details.json?limit=999999"
,
]
stubbed_api_response
=
load_stub_file_content
(
oar_api
)
stubbed_addresses
.
each
do
|
stubbed_address
|
stub_request
(
:get
,
stubbed_address
).
with
(
headers:
{
'Accept'
=>
'*/*'
,
}).
to_return
(
status:
200
,
body:
stubbed_api_response
,
headers:
{})
end
# Overload the 'load_data_hierarchy' to simulate the addition of a fake site in the input files
expect_any_instance_of
(
Object
).
to
receive
(
:load_data_hierarchy
).
and_return
(
JSON
::
parse
(
load_stub_file_content
(
data_hierarchy
)))
end
describe
'OarProperties'
do
describe
'OarProperties'
do
context
'testing arguments'
do
context
'testing arguments'
do
...
...
This diff is collapsed.
Click to expand it.
spec/spec_helper.rb
+
63
−
0
View file @
caa7ffe7
...
@@ -8,3 +8,66 @@ end
...
@@ -8,3 +8,66 @@ end
# This outputs the report to your public folder
# This outputs the report to your public folder
# You will want to add this to .gitignore
# You will want to add this to .gitignore
SimpleCov
.
coverage_dir
'coverage'
SimpleCov
.
coverage_dir
'coverage'
require
'rspec'
require
'webmock/rspec'
$LOAD_PATH
.
unshift
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'../lib'
)))
require
'refrepo'
require
'refrepo/gen/oar-properties'
STUBDIR
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
WebMock
.
disable_net_connect!
(
allow_localhost:
true
)
def
load_stub_file_content
(
stub_filename
)
if
not
File
.
exist?
(
"
#{
STUBDIR
}
/stub_oar_properties/
#{
stub_filename
}
"
)
raise
(
"Cannot find
#{
stub_filename
}
in '
#{
STUBDIR
}
/stub_oar_properties/'"
)
end
return
IO
.
read
(
"
#{
STUBDIR
}
/stub_oar_properties/
#{
stub_filename
}
"
)
end
# This code comes from https://gist.github.com/herrphon/2d2ebbf23c86a10aa955
# and enables to capture all output made on stdout and stderr by a block of code
def
capture
(
&
_block
)
begin
$stdout
=
StringIO
.
new
$stderr
=
StringIO
.
new
yield
result
=
{}
result
[
:stdout
]
=
$stdout
.
string
result
[
:stderr
]
=
$stderr
.
string
ensure
$stdout
=
STDOUT
$stderr
=
STDERR
end
result
end
def
str_block_to_regexp
(
str
)
str1
=
str
.
gsub
(
"|"
,
"
\\\\
|"
)
str2
=
str1
.
gsub
(
"+"
,
"
\\\\
+"
)
return
Regexp
.
new
str2
end
def
prepare_stubs
(
oar_api
,
data_hierarchy
)
conf
=
RefRepo
::
Utils
.
get_api_config
stubbed_addresses
=
[
"
#{
conf
[
"uri"
]
}
"
,
"
#{
conf
[
"uri"
]
}
/oarapi/resources/details.json?limit=999999"
,
"
#{
conf
[
"uri"
]
}
stable/sites/fakesite/internal/oarapi/resources/details.json?limit=999999"
,
]
stubbed_api_response
=
load_stub_file_content
(
oar_api
)
stubbed_addresses
.
each
do
|
stubbed_address
|
stub_request
(
:get
,
stubbed_address
).
with
(
headers:
{
'Accept'
=>
'*/*'
,
}).
to_return
(
status:
200
,
body:
stubbed_api_response
,
headers:
{})
end
# Overload the 'load_data_hierarchy' to simulate the addition of a fake site in the input files
expect_any_instance_of
(
Object
).
to
receive
(
:load_data_hierarchy
).
and_return
(
JSON
::
parse
(
load_stub_file_content
(
data_hierarchy
)))
end
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