Skip to content

Commit ce49fed

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] refactor setup_server to capture msgs from session
1 parent 7a6a323 commit ce49fed

File tree

13 files changed

+53
-44
lines changed

13 files changed

+53
-44
lines changed

server/tests/diagnostics/ols01000.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::setup::setup::*;
77

88
#[test]
99
fn test_ols01000() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01000.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
assert_eq!(diagnostics.len(), 1);
1516
let diag = &diagnostics[0];

server/tests/diagnostics/ols01001.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{setup::setup::*, test_utils::diag_on_line};
77

88
#[test]
99
fn test_ols01001() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01001.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
let diagnostics = diag_on_line(&diagnostics, 1);
1516
assert_eq!(diagnostics.len(), 1);

server/tests/diagnostics/ols01002.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{setup::setup::*, test_utils::diag_on_line};
77

88
#[test]
99
fn test_ols01002() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01002.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
let diagnostics = diag_on_line(&diagnostics, 2);
1516
assert_eq!(diagnostics.len(), 1);

server/tests/diagnostics/ols01003.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::setup::setup::*;
77

88
#[test]
99
fn test_ols01003() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01003.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
assert_eq!(diagnostics.len(), 1);
1516
let diag = &diagnostics[0];

server/tests/diagnostics/ols01004.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{setup::setup::*, test_utils::diag_on_line};
77

88
#[test]
99
fn test_ols01004() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01004.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
assert_eq!(diagnostics.len(), 1);
1516
let diagnostics = diag_on_line(&diagnostics, 33);

server/tests/diagnostics/ols01005.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{setup::setup::*, test_utils::diag_on_line};
77

88
#[test]
99
fn test_ols01005() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01005.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
assert_eq!(diagnostics.len(), 1);
1516
let diagnostics = diag_on_line(&diagnostics, 6);

server/tests/diagnostics/ols01006.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{setup::setup::*, test_utils::diag_on_line};
77

88
#[test]
99
fn test_ols01006() {
10-
let mut odoo = setup_server(false);
10+
let (mut odoo, config) = setup_server(false);
11+
let mut session = create_init_session(&mut odoo, config);
1112
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01006.py").sanitize();
12-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
13+
prepare_custom_entry_point(&mut session, &path);
1314
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1415
assert_eq!(diagnostics.len(), 1);
1516
let diagnostics = diag_on_line(&diagnostics, 14);

server/tests/diagnostics/ols01007.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use crate::{setup::setup::*, test_utils::{verify_diagnostics_against_doc}};
66

77
#[test]
88
fn test_ols01007() {
9-
let mut odoo = setup_server(false);
9+
let (mut odoo, config) = setup_server(false);
10+
let mut session = create_init_session(&mut odoo, config);
1011
let path = env::current_dir().unwrap().join("tests/data/python/diagnostics/ols01007.py").sanitize();
11-
let mut session = prepare_custom_entry_point(&mut odoo, &path);
12+
prepare_custom_entry_point(&mut session, &path);
1213
let diagnostics = get_diagnostics_for_path(&mut session, &path);
1314
let doc_diags = get_diagnostics_test_comments(&mut session, &path);
1415
verify_diagnostics_against_doc(diagnostics, doc_diags);

server/tests/setup/setup.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing::{info, level_filters::LevelFilter};
1616
use tracing_appender::rolling::RollingFileAppender;
1717
use tracing_subscriber::{fmt, layer::SubscriberExt, FmtSubscriber};
1818

19-
pub fn setup_server(with_odoo: bool) -> SyncOdoo {
19+
pub fn setup_server(with_odoo: bool) -> (SyncOdoo, ConfigEntry) {
2020

2121
let file_appender = RollingFileAppender::builder()
2222
.max_log_files(20) // only the most recent 5 log files will be kept
@@ -56,32 +56,27 @@ pub fn setup_server(with_odoo: bool) -> SyncOdoo {
5656
};
5757
config.python_path = python_cmd;
5858
config.diag_missing_imports = DiagMissingImportsMode::All;
59+
(server, config)
60+
}
5961

62+
pub fn create_init_session<'a>(odoo: &'a mut SyncOdoo, config: ConfigEntry) -> SessionInfo<'a> {
6063
let (s, r) = crossbeam_channel::unbounded();
61-
let mut session = SessionInfo::new_from_custom_channel(s, r, &mut server);
64+
let mut session = SessionInfo::new_from_custom_channel(s.clone(), r.clone(), odoo);
6265
session.sync_odoo.test_mode = true;
6366
SyncOdoo::init(&mut session, config);
64-
65-
server
66-
}
67-
68-
pub fn create_session(odoo: &mut SyncOdoo) -> SessionInfo {
69-
let (s, r) = crossbeam_channel::unbounded();
70-
SessionInfo::new_from_custom_channel(s.clone(), r.clone(), odoo)
67+
session
7168
}
7269

73-
pub fn prepare_custom_entry_point<'a>(odoo: &'a mut SyncOdoo, path: &str) -> SessionInfo<'a>{
74-
let mut session = create_session(odoo);
70+
pub fn prepare_custom_entry_point(session: &mut SessionInfo, path: &str){
7571
let ep_path = PathBuf::from(path).sanitize();
7672
let text = fs::read_to_string(path).expect("unable to read provided path");
7773
let content = Some(vec![TextDocumentContentChangeEvent{
7874
range: None,
7975
range_length: None,
8076
text: text}]);
81-
EntryPointMgr::create_new_custom_entry_for_path(&mut session, &ep_path, &ep_path);
82-
let (file_updated, file_info) = session.sync_odoo.get_file_mgr().borrow_mut().update_file_info(&mut session, path, content.as_ref(), Some(1), false);
83-
SyncOdoo::process_rebuilds(&mut session, false);
84-
session
77+
EntryPointMgr::create_new_custom_entry_for_path(session, &ep_path, &ep_path);
78+
let (file_updated, file_info) = session.sync_odoo.get_file_mgr().borrow_mut().update_file_info(session, path, content.as_ref(), Some(1), false);
79+
SyncOdoo::process_rebuilds(session, false);
8580
}
8681

8782
pub fn get_diagnostics_for_path(session: &mut SessionInfo, path: &str) -> Vec<Diagnostic> {

server/tests/test_basics.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ mod setup;
1414
#[test]
1515
fn test_no_main_entry() {
1616
/* First, let's launch the server. It will setup a SyncOdoo struct, with a SyncChannel, that we can use to get the messages that the client would receive. */
17-
let odoo = setup::setup::setup_server(false);
17+
let (mut odoo, config) = setup::setup::setup_server(false);
18+
let _ = setup::setup::create_init_session(&mut odoo, config);
1819
assert!(!odoo.has_main_entry);
1920
assert!(!odoo.has_odoo_main_entry);
2021
assert!(odoo.entry_point_mgr.borrow().main_entry_point.is_none());
@@ -23,18 +24,20 @@ fn test_no_main_entry() {
2324

2425
#[test]
2526
fn test_custom_entry_point() {
26-
let mut odoo = setup::setup::setup_server(false);
27+
let (mut odoo, config) = setup::setup::setup_server(false);
28+
let mut session = setup::setup::create_init_session(&mut odoo, config);
2729
let path = env::current_dir().unwrap().join("tests/data/python/expressions/assign.py");
28-
let session = setup::setup::prepare_custom_entry_point(&mut odoo, path.sanitize().as_str());
30+
setup::setup::prepare_custom_entry_point(&mut session, path.sanitize().as_str());
2931
assert!(odoo.entry_point_mgr.borrow().custom_entry_points.len() == 1);
3032
}
3133

3234

3335
#[test]
3436
fn test_assigns() {
35-
let mut odoo = setup::setup::setup_server(false);
37+
let (mut odoo, config) = setup::setup::setup_server(false);
38+
let mut session = setup::setup::create_init_session(&mut odoo, config);
3639
let path = env::current_dir().unwrap().join("tests/data/python/expressions/assign.py").sanitize();
37-
let session = setup::setup::prepare_custom_entry_point(&mut odoo, path.as_str());
40+
setup::setup::prepare_custom_entry_point(&mut session, path.as_str());
3841
assert!(session.sync_odoo.entry_point_mgr.borrow().custom_entry_points.len() == 1);
3942
let a = session.sync_odoo.get_symbol(path.as_str(), &(vec![], vec![Sy!("a")]), u32::MAX);
4043
assert!(a.len() == 1);
@@ -145,9 +148,10 @@ fn test_assigns() {
145148

146149
#[test]
147150
fn test_sections() {
148-
let mut odoo = setup::setup::setup_server(false);
151+
let (mut odoo, config) = setup::setup::setup_server(false);
152+
let mut session = setup::setup::create_init_session(&mut odoo, config);
149153
let path = env::current_dir().unwrap().join("tests/data/python/expressions/sections.py").sanitize();
150-
let session = setup::setup::prepare_custom_entry_point(&mut odoo, path.as_str());
154+
setup::setup::prepare_custom_entry_point(&mut session, path.as_str());
151155
assert!(session.sync_odoo.entry_point_mgr.borrow().custom_entry_points.len() == 1);
152156

153157
let assert_get_int_eval_values = |var_name: &str, values: HashSet<i32>|{

0 commit comments

Comments
 (0)