'testthat', how should I interpret this failure? - r

I want to use 'testthat' to add tests to my package.
This is my test-file:
library(RBaseX)
test_that("Credentials are accepted", {
skip_unless_socket_available()
expect_error(BasexClient$new("localhost", 1984L, username = "admin", password = "denied"), "Access denied")
Session <- BasexClient$new("localhost", 1984L, username = "admin", password = "admin")
expect_equal(class(Session)[[1]], "BasexClient")
})
skip_unless_socket_available is defined in a separate helper.R-file:
skip_unless_socket_available <- function() {
tryCatch({
Socket <- socketConnection(host = "localhost", 1984,
open = "w+b", server = FALSE, blocking = TRUE, encoding = "utf-8")
close(Socket)
TRUE
}, error = function(e) {
skip(paste0("basexserver not available:\n'", conditionMessage(e), "'"))
})
}
When the program is executed I get this output:
Loading RBaseX
Testing RBaseX
✓ | OK F W S | Context
✓ | 2 | test_RbaseX [0.2 s]
⠹ | 2 1 | test_RbaseX
══ Results ═══════════════════════════════
Duration: 0.3 s
OK: 2
Failed: 1
Warnings: 0
Skipped: 0
No matter what I do, I still get 1 failure. Both exceptions, however, are handled correctly.
How should I act upon this failure?
Ben
After inserting 3 contexts() in test_RBaseX.R, I now get this output:
Loading RBaseX
Testing RBaseX
✓ | OK F W S | Context
✓ | 2 | Access [0.1 s]
✓ | 2 | Create Session [0.1 s]
⠏ | 0 | Check setter/getter (and BasexClient$Execute())
✓ | 2 | Check setter/getter (and BasexClient$Execute())
⠏ | 0 | Intercept set/get is handled correctlyDatabase 'TestOpen' is niet gevonden.
Database 'TestOpen' is niet gevonden.
Database 'TestOpen' is niet gevonden.
✓ | 1 | Intercept set/get is handled correctly
⠙ | 1 1 | Intercept set/get is handled correctly
══ Results ════════════════════════════════════════════
Duration: 0.4 s
OK: 7
Failed: 1
Warnings: 0
Skipped: 0
All tests give the expected result but then 1 failure is added. I still haven't seen any indication why.
Does this help?
Ben
(By the way, thanks to these testing-activities, I found and fixed serveral errors :-))

After moving the file 'testthat.R' from the '/tests/testthat'-directory, to the '/tests'-directory, there were no failures detected anymore.
Ben

Related

How can I aggregate fields based on the value of another field?

I have an Azure hosted application in which some of our users have been complaining of difficulty logging-in. So I added some logs which show up in Application Insights. A sample of the data is shown below:
I need to create a report that shows:
The number of unique users (the Identifier field) that successfully logged-in and the number of unique users that failed to login.
The number of failed login attempts that preceded a successful attempt (if any) - is this even possible in KQL?
One one my attempts was:
customEvents
| order by timestamp asc
| summarize TotalUserCount=dcount(tostring(customDimensions["Identifier"])),
SuccessCount=countif(name startswith "Success"),
FailureCount=countif(name !startswith "Success")
But this is wrong, I need countif(name...) to also be distinct by Identifier.
I'm new to KQL and so would appreciate some help.
Thanks.
I would start from analyzing the data in the session level.
It's very easy to take it from there and summarize it to the user level etc.
// Data sample generation. Not part of the solution
// Setup
let p_event_num = 30;
let p_identifiers_num = 3;
let p_max_distance_between_events = 2h;
let p_names = dynamic(["Unsuccessful login. Invalid cred", "Unsuccessful login. Account wa", "Successful login"]);
// Internal
let p_identifiers = toscalar(range i from 1 to p_identifiers_num step 1 | summarize make_list(new_guid()));
let p_names_num = array_length(p_names);
let customEvents = materialize
(
range i from 1 to p_event_num step 1
| extend ['timestamp [UTC]'] = ago(24h*rand())
| extend Identifier = tostring(p_identifiers[toint(rand(p_identifiers_num))])
| extend name = p_names[toint(rand(p_names_num))]
);
// Solution starts here
customEvents
| project-rename ts = ['timestamp [UTC]']
| partition hint.strategy=native by Identifier
(
order by ts asc
| extend session_id = row_cumsum(iff(ts - prev(ts) >= p_max_distance_between_events, 1, 0))
| summarize session_start = min(ts)
,session_end = max(ts)
,session_duration = 0s
,session_events = count()
,session_successes = countif(name startswith "Successful")
,session_failures = countif(name !startswith "Successful")
,arg_max(ts, name)
by Identifier, session_id
)
| project-away ts
| project-rename session_last_name = name
| extend session_duration = session_end - session_start
| order by Identifier asc, session_id asc
| as user_sessions
Identifier
session_id
session_start
session_end
session_duration
session_events
session_successes
session_failures
session_last_name
3b169e06-52e5-45d8-b951-62d5e8ab385b
0
2022-06-26T20:22:22.4006737Z
2022-06-26T20:22:22.4006737Z
00:00:00
1
0
1
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
1
2022-06-26T22:47:01.8487347Z
2022-06-26T22:47:01.8487347Z
00:00:00
1
1
0
Successful login
3b169e06-52e5-45d8-b951-62d5e8ab385b
2
2022-06-27T04:57:15.6405722Z
2022-06-27T07:32:10.4409854Z
02:34:54.8004132
4
1
3
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
3
2022-06-27T10:44:19.8739205Z
2022-06-27T12:46:14.2586725Z
02:01:54.3847520
3
0
3
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
4
2022-06-27T14:50:35.3882433Z
2022-06-27T14:50:35.3882433Z
00:00:00
1
0
1
Unsuccessful login. Account wa
3b169e06-52e5-45d8-b951-62d5e8ab385b
5
2022-06-27T18:33:51.4464796Z
2022-06-27T18:47:06.0628481Z
00:13:14.6163685
2
0
2
Unsuccessful login. Invalid cred
63ce6481-818e-4f3b-913e-88a1b76ac423
0
2022-06-26T19:27:05.1220534Z
2022-06-26T20:24:53.5616443Z
00:57:48.4395909
2
0
2
Unsuccessful login. Account wa
63ce6481-818e-4f3b-913e-88a1b76ac423
1
2022-06-27T02:17:03.4123257Z
2022-06-27T02:36:50.1918116Z
00:19:46.7794859
3
1
2
Successful login
63ce6481-818e-4f3b-913e-88a1b76ac423
2
2022-06-27T13:27:27.2550722Z
2022-06-27T14:32:39.6361479Z
01:05:12.3810757
3
2
1
Successful login
63ce6481-818e-4f3b-913e-88a1b76ac423
3
2022-06-27T17:20:34.3725797Z
2022-06-27T17:20:34.3725797Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
0
2022-06-26T22:38:39.3105749Z
2022-06-26T22:38:39.3105749Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
1
2022-06-27T03:06:04.340965Z
2022-06-27T04:49:37.3314224Z
01:43:32.9904574
3
3
0
Successful login
6ed81ab3-447e-481d-8bb3-a5f4087234bb
2
2022-06-27T07:11:47.260913Z
2022-06-27T07:11:47.260913Z
00:00:00
1
0
1
Unsuccessful login. Account wa
6ed81ab3-447e-481d-8bb3-a5f4087234bb
3
2022-06-27T11:39:02.356791Z
2022-06-27T16:49:23.5818891Z
05:10:21.2250981
4
2
2
Unsuccessful login. Invalid cred
Fiddle
I need countif(name...) to also be distinct by Identifier.
If I understood your intention correctly, you could use dcountif().
For example:
customEvents
| where timestamp > ago(1d)
| extend Identifier = tostring(customDimensions["Identifier"])
| summarize TotalUserCount = dcount(Identifier),
SuccessCount = dcountif(Identifier, name startswith "Success"),
FailureCount = dcountif(Identifier, name !startswith "Success")
The number of failed login attempts that preceded a successful attempt (if any) - is this even possible in KQL?
You could try using the scan operator for this: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/scan-operator

julia 1.0 installation tests - nix-pkgs - ubuntu

My laptop:
Linux g-TP 4.13.0-26-generic #29~16.04.2-Ubuntu SMP Tue Jan 9 22:00:44
UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
I installed julia via nix-env and got the following test result
Test Summary: | Pass Broken Total
Overall | 37420635 327815 37748450
SUCCESS
What can / should I do for resolving the 327815 broken tests?
A test that is marked as broken (with #test_broke) does not lead to a test failure, all tests passed as indicated by the SUCCESS in the output.
From the docs of #test_broken:
help?> #test_broken
#test_broken ex
Indicates a test that should pass but currently consistently fails.
Tests that the expression ex evaluates to false or causes an exception.
Returns a Broken Result if it does, or an Error Result if the expression evaluates to true.
Example:
julia> using Test
julia> #testset begin
#test 1 == 1 # results in a Pass
#test 1 == 2 # results in a Fail
#test_broken 1 == 2 # results in a Broken
end
Test Summary: | Pass Fail Broken Total
test set | 1 1 1 3
ERROR: Some tests did not pass: 1 passed, 1 failed, 0 errored, 1 broken.

orientdb SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty

I have this file that I'm trying to import on orientdb it has the following structure :
p1 p2 combined_score
1 568703.LGG_00001 568703.LGG_01682 282
2 568703.LGG_00001 568703.LGG_01831 183
3 568703.LGG_00001 568703.LGG_01491 238
I'm doing the import using oetl :
{
"source": { "file": { "path": "C:/Users/Desktop/files/file22/lac2.csv" } },
"extractor": { "csv": {} },
"transformers": [
{ "vertex": { "class": "nodes" } }
],
"loader": {
"orientdb": {
"dbURL": "plocal:/tmp/databases/db/db",
"dbType": "graph",
"classes": [
{"name": "nodes", "extends": "V"},
]
}
}
}
Trying to import the vertices first and then the nodes .
Yet I'm getting this error
2017-06-26 18:38:27:059 SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty [OETLProcessor$OETLExtractorWorker]+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 2012ms [0 warnings, 0 errors]
+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 3033ms [0 warnings, 0 errors]
+ extracted 0 rows (0 rows/sec) - 0 rows -> loaded 0 vertices (0 vertices/sec) Total time: 4033ms [0 warnings, 0 errors]
Nothing is loading ,How can I solve this ?
I'm using orientdb community-2.2.18 and tried 2.2.22 vrsion too and the problem is percisting
This message:
2017-06-26 18:38:27:059 SEVER Error during extraction: java.lang.IllegalArgumentException: Field name is empty
is because in your csv file, the name of the property in blank, you can modify your csv file in this way without giving it a name:
p1,p2,combined_score
1,568703.LGG_00001,568703.LGG_01682,282
2,568703.LGG_00001,568703.LGG_01831,183
3,568703.LGG_00001,568703.LGG_01491,238
and this will be your output:
+----+-----+------+----+----------------+----------------+
|# |#RID |#CLASS|p1 |combined_score |p2 |
+----+-----+------+----+----------------+----------------+
|0 |#17:0|nodes |1 |568703.LGG_01682|568703.LGG_00001|
|1 |#18:0|nodes |2 |568703.LGG_01831|568703.LGG_00001|
|2 |#19:0|nodes |3 |568703.LGG_01491|568703.LGG_00001|
+----+-----+------+----+----------------+----------------+
otherwise, if you wanna give it a name, do it in this way:
id,p1,p2,combined_score
1,568703.LGG_00001,568703.LGG_01682,282
2,568703.LGG_00001,568703.LGG_01831,183
3,568703.LGG_00001,568703.LGG_01491,238
and this will be the output:
+----+-----+------+----------------+--------------+----------------+----+
|# |#RID |#CLASS|p1 |combined_score|p2 |id |
+----+-----+------+----------------+--------------+----------------+----+
|0 |#17:0|nodes |568703.LGG_00001|282 |568703.LGG_01682|1 |
|1 |#18:0|nodes |568703.LGG_00001|183 |568703.LGG_01831|2 |
|2 |#19:0|nodes |568703.LGG_00001|238 |568703.LGG_01491|3 |
+----+-----+------+----------------+--------------+----------------+----+
I tried with 2.2.22.
Hope it helps.
Regards

How to print git history in rmarkdown?

I am writing an analysis report with rmarkdown and would like to have a "document versions" section in which I would indicate the different versions of the document and the changes made.
Instead of writing it down manually, I was thinking about using git history and inserting it automatically in the markdown document (formatting it in a table).
How can I do that? Is it possible?
Install git2r, https://github.com/ropensci/git2r then you can do stuff like:
> r = repository(".")
> cs = commits(r)
> cs[[1]]
[02cf9a0] 2017-02-02: uses Rcpp attributes instead of inline
So now I have a list of all the commits on this repo. You can get the info out of each commit and format as per your desire into your document.
> summary(cs[[1]])
Commit: 02cf9a0ff92d3f925b68853374640596530c90b5
Author: barryrowlingson <b.rowlingson#gmail.com>
When: 2017-02-02 23:03:17
uses Rcpp attributes instead of inline
11 files changed, 308 insertions, 151 deletions
DESCRIPTION | - 0 + 2 in 2 hunks
NAMESPACE | - 0 + 2 in 1 hunk
R/RcppExports.R | - 0 + 23 in 1 hunk
R/auxfunctions.R | - 1 + 1 in 1 hunk
R/skewt.r | - 0 + 3 in 1 hunk
R/update_params.R | - 1 + 1 in 1 hunk
R/update_params_cpp.R | -149 + 4 in 2 hunks
src/.gitignore | - 0 + 3 in 1 hunk
src/RcppExports.cpp | - 0 + 76 in 1 hunk
src/hello_world.cpp | - 0 + 13 in 1 hunk
src/update_params.cpp | - 0 +180 in 1 hunk
So if you just want the time and the commit message then you can grab it out of the object.
> cs[[3]]#message
[1] "fix imports etc\n"
> cs[[3]]#committer#when
2017-01-20 23:26:20
I don't know if there's proper accessor functions for these rather than using #-notation to get slots. Need to read the docs a bit more...
You can make a data frame from your commits this way:
> do.call(rbind,lapply(cs,function(cs){as(cs,"data.frame")}))
which converts the dates to POSIXct objects, which is nice. Creating a markdown table from the data frame should be trivial!
You can manually convert git log to markdown with pretty=format [1]
Something like
git log --reverse --pretty=format:'| %H | %s |'
This will output something like this:
| a8d5defb511f1e44ddea21b42aec9b03ee768253 | initial commit |
| fdd9865e9cf01bd53c4f1dc106ee603b0a730f48 | fix tests |
| 10b58e8dd9cf0b9bebbb520408f0b342df613627 | add Dockerfile |
| d039004e8073a20b5d6eab1979c1afa213b78fa3 | update README.md |
1: https://git-scm.com/docs/pretty-formats

Compare stored values in Selenium IDE

I am new to test automation and to Selenium IDE. With Selenium IDE, I want to store two values(integer) and compare them. Test passes if the compared result is greater than or equal to zero. So far, I only found an option to store the values and wondering if there is any option to compare the stored values.
Any suggestion would be helpful.
Thanks
Okay, assuming you're always subtracting A (constant value) from B(variable value), you can use some javascript to perform the test.
store | 2 | A
store | 4 | B
storeEval | var s = false; s = eval((storedVars['B'] - storedVars['A']) >=0); | s
verifyExpression | ${s}
replace the two store steps above with whatever you use to get your variables A and B.
The verifyExpression line will pass(return true) if result is greater than or equal to zero, will fail(stay false) if not.
store |2| A
store |4| B
storeEval |var s = false; s = eval((storedVars['B'] - storedVars['A']) >=0);| s
echo |${s}|
Executing: |store | 2 | A |
Executing: |store | 4 | B |
Executing: |storeEval | var s = false; s = eval((storedVars['B'] - storedVars['A']) >=0); | s |
script is: var s = false; s = eval((storedVars['B'] - storedVars['A']) >=0);
Executing: |echo | ${s} | |
echo: true
Test case passed

Resources