Skip to content

Commit 3c3ea39

Browse files
committed
changes to testfile
1 parent 493b741 commit 3c3ea39

File tree

3 files changed

+59
-61
lines changed

3 files changed

+59
-61
lines changed

Project.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ DBCtoDBF_jll = "404e8f35-d372-56c3-89ac-e648a26fddda"
88
DBFTables = "75c7ada1-017a-5fb6-b8c7-2125ff2d6c93"
99
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1010
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
11-
12-
1311
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
1412

15-
16-
1713
[compat]
14+
DBCtoDBF_jll = "v1.0.0"
1815
DBFTables = "1.2.6"
1916
DataFrames = "1.6.1"
2017
Documenter = "1.6.0"
2118
julia = "1.10.4"
2219

23-
DBCtoDBF_jll = "v1.0.0"
24-
25-
2620
[extras]
2721
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2822

src/ReadDBC.jl

+36-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
1-
# test/test_read_dbc.jl
2-
using Test # Import the Test package to write test cases
3-
using ReadDBC # Import your module to test its functions
1+
module ReadDBC
2+
3+
# Export functions
4+
export dbcTable, dbctodbf
5+
6+
# Importing packages
7+
using DBFTables
48
using DataFrames
59

6-
# Define paths for test input and expected output
7-
input_file = "src/ABOAC1909.dbc"
8-
output_file = "src/ABOAC1909.dbf"
10+
using DBCtoDBF_jll
911

10-
@testset "ReadDBC Module Tests" begin
1112

12-
# Test 1: Test dbctodbf function
13-
@testset "Test dbctodbf" begin
14-
@test isfile(input_file) # Check if the input file exists
15-
result = dbctodbf(input_file, output_file) # Call the function
16-
@test result == output_file # Ensure the output file path is returned
17-
@test isfile(output_file) # Check if the output file was created
18-
end
1913

20-
# Test 2: Test dbcTable function
21-
@testset "Test dbcTable" begin
22-
df = dbcTable(input_file) # Call the function to convert and read
23-
@test df !== nothing # Ensure the DataFrame is not empty
24-
@test isa(df, DataFrame) # Ensure the result is a DataFrame
25-
@test nrow(df) > 0 # Ensure the DataFrame has rows
14+
# Defining function dbctodbf
15+
function dbctodbf(input_file::String, output_file::String)
16+
# The DBCtoDBF_jll package provides the dbc2dbf executable directly
17+
exe_path = dbc2dbf() # This gives the path to the dbc2dbf executable
18+
19+
# Run the executable with the input and output file arguments
20+
run(`$exe_path $input_file $output_file`)
21+
22+
return output_file # Optionally return the output file name
23+
end
24+
25+
# Defining function readdbc
26+
function dbcTable(input_file::String)
27+
output_file = replace(input_file, ".dbc" => ".dbf")
28+
try
29+
# Convert the DBC file to a DBF file
30+
dbctodbf(input_file, output_file)
31+
32+
# Read the DBF file into a DataFrame
33+
df = DBFTables.Table(output_file)
34+
return DataFrame(df)
35+
36+
catch e
37+
@error "Failed to convert or read DBC file: $input_file"
38+
@error "$e"
39+
return nothing
2640
end
41+
end
2742

28-
end
43+
end # module readdbc

test/runtests.jl

+22-33
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,28 @@
1-
using Test
2-
using ReadDBC
1+
2+
using Test # Import the Test package to write test cases
3+
using ReadDBC # Import your module to test its functions
34
using DataFrames
45

6+
# Define paths for test input and expected output
7+
input_file = "src/ABOAC1909.dbc"
8+
output_file = "src/ABOAC1909.dbf"
59

6-
# Test the dbctodbf function
7-
@testset "ReadDBC Tests" begin
8-
# Set up file paths
9-
input_file = "src/ABOAC1909.dbc"
10-
output_file = "src/ABOAC1909.dbf"
11-
dbctodbf(input_file, output_file)
12-
13-
# Check if the output file is created (basic test)
14-
@test isfile(output_file)
10+
@testset "ReadDBC Module Tests" begin
1511

16-
# Clean up (remove files)
17-
rm(output_file)
18-
end
12+
# Test 1: Test dbctodbf function
13+
@testset "Test dbctodbf" begin
14+
@test isfile(input_file) # Check if the input file exists
15+
result = dbctodbf(input_file, output_file) # Call the function
16+
@test result == output_file # Ensure the output file path is returned
17+
@test isfile(output_file) # Check if the output file was created
18+
end
1919

20-
# Test the readdbc function
21-
@testset "ReadDBC Tests" begin
22-
# Set up file paths
23-
input_file = "src/ABOAC1909.dbc"
24-
output_file = replace(input_file, ".dbc" => ".dbf")
25-
26-
# Call the readdbc function
27-
df = dbcTable(input_file)
28-
29-
# Ensure the DataFrame is returned and is not empty (this depends on actual implementation)
30-
@test df !== nothing
31-
@test isa(df, DataFrame)
32-
33-
# Add more tests as needed, for example, checking specific columns or data in the DataFrame
34-
35-
# Clean up (remove files)
36-
rm(output_file)
37-
end
20+
# Test 2: Test dbcTable function
21+
@testset "Test dbcTable" begin
22+
df = dbcTable(input_file) # Call the function to convert and read
23+
@test df !== nothing # Ensure the DataFrame is not empty
24+
@test isa(df, DataFrame) # Ensure the result is a DataFrame
25+
@test nrow(df) > 0 # Ensure the DataFrame has rows
26+
end
3827

39-
println("All tests passed successfully.")
28+
end

0 commit comments

Comments
 (0)