You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/02/26 19:56:56 UTC

[arrow] branch master updated: ARROW-4634: [Rust] [Parquet] Reorganize test_common

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new f1d6dea  ARROW-4634: [Rust] [Parquet] Reorganize test_common
f1d6dea is described below

commit f1d6dea59dfb5f7c54ab8487367b2d6bc6cf6987
Author: Renjie Liu <li...@gmail.com>
AuthorDate: Tue Feb 26 13:56:46 2019 -0600

    ARROW-4634: [Rust] [Parquet] Reorganize test_common
    
    Currently test_common mod is just one file, and when we need to add more test utils into it, things may messed up, so I propose to make test_common a directory with multi sub mods.
    
    @andygrove @sunchao Please help to review this.
    
    Author: Renjie Liu <li...@gmail.com>
    
    Closes #3710 from liurenjie1024/test-common and squashes the following commits:
    
    ae3d25f1 <Renjie Liu> Fix some style broken problems
    9495bbc0 <Renjie Liu> Reorganize test_common
---
 rust/parquet/src/util/test_common/file_util.rs     | 62 ++++++++++++++++++++++
 rust/parquet/src/util/test_common/mod.rs           | 29 ++++++++++
 .../{test_common.rs => test_common/rand_gen.rs}    | 45 ----------------
 3 files changed, 91 insertions(+), 45 deletions(-)

diff --git a/rust/parquet/src/util/test_common/file_util.rs b/rust/parquet/src/util/test_common/file_util.rs
new file mode 100644
index 0000000..ec192a3
--- /dev/null
+++ b/rust/parquet/src/util/test_common/file_util.rs
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+use std::{env, fs, io::Write, path::PathBuf, str::FromStr};
+
+/// Returns path to the test parquet file in 'data' directory
+pub fn get_test_path(file_name: &str) -> PathBuf {
+    let result = env::var("PARQUET_TEST_DATA");
+    if result.is_err() {
+        panic!("Please point PARQUET_TEST_DATA environment variable to the test data directory");
+    }
+    let mut pathbuf = PathBuf::from_str(result.unwrap().as_str()).unwrap();
+    pathbuf.push(file_name);
+    pathbuf
+}
+
+/// Returns file handle for a test parquet file from 'data' directory
+pub fn get_test_file(file_name: &str) -> fs::File {
+    let file = fs::File::open(get_test_path(file_name).as_path());
+    if file.is_err() {
+        panic!("Test file {} not found", file_name)
+    }
+    file.unwrap()
+}
+
+/// Returns file handle for a temp file in 'target' directory with a provided content
+pub fn get_temp_file(file_name: &str, content: &[u8]) -> fs::File {
+    // build tmp path to a file in "target/debug/testdata"
+    let mut path_buf = env::current_dir().unwrap();
+    path_buf.push("target");
+    path_buf.push("debug");
+    path_buf.push("testdata");
+    fs::create_dir_all(&path_buf).unwrap();
+    path_buf.push(file_name);
+
+    // write file content
+    let mut tmp_file = fs::File::create(path_buf.as_path()).unwrap();
+    tmp_file.write_all(content).unwrap();
+    tmp_file.sync_all().unwrap();
+
+    // return file handle for both read and write
+    let file = fs::OpenOptions::new()
+        .read(true)
+        .write(true)
+        .open(path_buf.as_path());
+    assert!(file.is_ok());
+    file.unwrap()
+}
diff --git a/rust/parquet/src/util/test_common/mod.rs b/rust/parquet/src/util/test_common/mod.rs
new file mode 100644
index 0000000..45cb772
--- /dev/null
+++ b/rust/parquet/src/util/test_common/mod.rs
@@ -0,0 +1,29 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+pub mod file_util;
+pub mod rand_gen;
+
+pub use self::rand_gen::random_bools;
+pub use self::rand_gen::random_bytes;
+pub use self::rand_gen::random_numbers;
+pub use self::rand_gen::random_numbers_range;
+pub use self::rand_gen::RandGen;
+
+pub use self::file_util::get_temp_file;
+pub use self::file_util::get_test_file;
+pub use self::file_util::get_test_path;
diff --git a/rust/parquet/src/util/test_common.rs b/rust/parquet/src/util/test_common/rand_gen.rs
similarity index 70%
rename from rust/parquet/src/util/test_common.rs
rename to rust/parquet/src/util/test_common/rand_gen.rs
index ad315a6..7b335e5 100644
--- a/rust/parquet/src/util/test_common.rs
+++ b/rust/parquet/src/util/test_common/rand_gen.rs
@@ -19,7 +19,6 @@ use rand::{
     distributions::{range::SampleRange, Distribution, Standard},
     thread_rng, Rng,
 };
-use std::{env, fs, io::Write, path::PathBuf, str::FromStr};
 
 use crate::data_type::*;
 use crate::util::memory::ByteBufferPtr;
@@ -144,47 +143,3 @@ where
         result.push(rng.gen_range(low, high));
     }
 }
-
-/// Returns path to the test parquet file in 'data' directory
-pub fn get_test_path(file_name: &str) -> PathBuf {
-    let result = env::var("PARQUET_TEST_DATA");
-    if result.is_err() {
-        panic!("Please point PARQUET_TEST_DATA environment variable to the test data directory");
-    }
-    let mut pathbuf = PathBuf::from_str(result.unwrap().as_str()).unwrap();
-    pathbuf.push(file_name);
-    pathbuf
-}
-
-/// Returns file handle for a test parquet file from 'data' directory
-pub fn get_test_file(file_name: &str) -> fs::File {
-    let file = fs::File::open(get_test_path(file_name).as_path());
-    if file.is_err() {
-        panic!("Test file {} not found", file_name)
-    }
-    file.unwrap()
-}
-
-/// Returns file handle for a temp file in 'target' directory with a provided content
-pub fn get_temp_file(file_name: &str, content: &[u8]) -> fs::File {
-    // build tmp path to a file in "target/debug/testdata"
-    let mut path_buf = env::current_dir().unwrap();
-    path_buf.push("target");
-    path_buf.push("debug");
-    path_buf.push("testdata");
-    fs::create_dir_all(&path_buf).unwrap();
-    path_buf.push(file_name);
-
-    // write file content
-    let mut tmp_file = fs::File::create(path_buf.as_path()).unwrap();
-    tmp_file.write_all(content).unwrap();
-    tmp_file.sync_all().unwrap();
-
-    // return file handle for both read and write
-    let file = fs::OpenOptions::new()
-        .read(true)
-        .write(true)
-        .open(path_buf.as_path());
-    assert!(file.is_ok());
-    file.unwrap()
-}