Skip to content

Commit ebfabcc

Browse files
authored
Test all (current) functionality for registration (#4)
* naming tests * tests for project setup * remove use of isnothing * optional git stuff * allow testing on appveyor * Removed submodule src/test project * test at a safe path!!!
1 parent 5e1c98d commit ebfabcc

File tree

8 files changed

+87
-26
lines changed

8 files changed

+87
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
DrWatson is a Julia package created to help people "deal" with their simulations, simulation parameters, where are files saved, experimental data, scripts, existing simulations, project source code and in general their scientific projects.
88

9-
**DrWatson is in pre-alpha. Wanna help development? Get involed by checking the issues and opening your own feature requests and suggestions.**
9+
**DrWatson is in beta. Wanna help development? Get involed by checking the issues and opening your own feature requests and suggestions.**
1010

1111
Please read the documentation page for more!

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ build_script:
3333

3434
test_script:
3535
- echo "%JL_TEST_SCRIPT%"
36+
- git config --global user.name "AppVeyor"
37+
- git config --global user.email "app@vey.or"
3638
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
3739

3840
# # Uncomment to support code coverage upload. Should only be enabled for packages

docs/src/project.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Seems like `src` and `scripts` folders have pretty similar functionality. Howeve
3333

3434
1. If upon `include("file.jl")` there is _anything_ being produced, be it data files, plots or even output to the console, then it should be in `scripts`.
3535
2. If it is functionality used across multiple files or pipelines, it should be in `src`.
36-
3. `src` should only contain files the define functions or modules but not output anything.
36+
3. `src` should only contain files the define functions or modules but not output anything. You can also organize `src` to be a Julia package, or contain multiple Julia packages.
3737

3838
## Initializing a Project
3939

docs/src/savenames.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Naming Schemes
44

5-
A robust naming scheme allows you to create quick names for simulations, create lists of simulations, check existing simulations, etc.
5+
A robust naming scheme allows you to create quick names for simulations, create lists of simulations, check existing simulations, etc.
66

77
```@docs
88
savename
@@ -13,6 +13,6 @@ DrWatson.access
1313

1414
Notice that the naming scheme integrates perfectly with Parameters.jl.
1515

16-
## Adding Runs
16+
## Creating Run Tables
1717

1818
WIP. (Adding simulation runs to a table/csv/dataframe)

src/project_setup.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,26 @@ The new project remains activated for you to immidiately add packages.
5151
Project.toml file.
5252
* `force = false` : If the `path` is _not_ empty then throw an error. If however `force`
5353
is `true` then recursively delete everything in the path and create the project.
54+
* `git = true` : Make the project a Git repository.
5455
"""
5556
function initialize_project(path, name = basename(path);
56-
force = false, readme = true, authors = nothing)
57+
force = false, readme = true, authors = nothing,
58+
git = true)
5759

58-
if !isempty(path)
60+
mkpath(path)
61+
rd = readdir(path)
62+
if length(rd) != 0
5963
if force
60-
for d in readdir(path)
61-
rm(d, recursive = true, force = true)
64+
for d in rd
65+
rm(joinpath(path, d), recursive = true, force = true)
6266
end
6367
else
6468
error("Project path is not empty!")
6569
end
6670
end
6771

68-
mkpath(path)
69-
repo = LibGit2.init(path)
70-
LibGit2.commit(repo, "Initial commit")
72+
if git; repo = LibGit2.init(path); end
73+
git && LibGit2.commit(repo, "Initial commit")
7174
Pkg.activate(path)
7275
# Pkg.add("DrWatson")#Uncomment when the package is released
7376
Pkg.add("Pkg")
@@ -77,28 +80,28 @@ function initialize_project(path, name = basename(path);
7780
mkpath(joinpath(path, p))
7881
end
7982

80-
LibGit2.add!(repo, "Project.toml")
81-
LibGit2.add!(repo, DEFAULT_PATHS...)
82-
LibGit2.commit(repo, "Folder setup by DrWatson")
83+
git && LibGit2.add!(repo, "Project.toml")
84+
git && LibGit2.add!(repo, DEFAULT_PATHS...)
85+
git && LibGit2.commit(repo, "Folder setup by DrWatson")
8386

8487
# Default files
8588
cp(joinpath(@__DIR__, "defaults", "gitignore.txt"), joinpath(path, ".gitignore"))
8689
cp(joinpath(@__DIR__, "defaults", "intro.jl"), joinpath(path, "scripts/intro.jl"))
8790
files = vcat(".gitignore", "/scripts/intro.jl")
8891
if readme
89-
write("README.md", DEFAULT_README)
92+
write(joinpath(path, "README.md"), DEFAULT_README)
9093
push!(files, "README.md")
9194
end
92-
pro = read("Project.toml", String)
95+
pro = read(joinpath(path, "Project.toml"), String)
9396
w = "name = \"$name\"\n"
94-
if !isnothing(authors)
97+
if !(authors === nothing)
9598
w *= "authors = "*sprint(show, vecstring(authors))*"\n"
9699
end
97-
write("Project.toml", w, pro)
100+
write(joinpath(path, "Project.toml"), w, pro)
98101
push!(files, "Project.toml")
99102

100-
LibGit2.add!(repo, files...)
101-
LibGit2.commit(repo, "File setup by DrWatson")
103+
git && LibGit2.add!(repo, files...)
104+
git && LibGit2.commit(repo, "File setup by DrWatson")
102105
return path
103106
end
104107

test/naming_tests.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using DrWatson, Test
2+
3+
d = (a = 0.153456453, b = 5.0, mode = "double")
4+
@test savename(d; digits = 4) == "a=0.1535_b=5_mode=double"
5+
@test savename(d, (String,)) == "mode=double"
6+
7+
rick = (never = "gonna", give = "you", up = "!");
8+
@test savename(rick) == "give=you_never=gonna_up=!"
9+
10+
x = 3; y = 5.0;
11+
d = Dict("x" => x, "y" => y)
12+
13+
@test d == @dict x y
14+
15+
z = "lala"
16+
d2 = Dict("x" => x, "y" => y, "z" => z)
17+
18+
@test d2 == @dict x y z
19+
20+
@test savename(@dict x y) == "x=3_y=5"
21+
w = rand(50)
22+
@test savename(@dict x y w) == savename(@dict x y)

test/project_tests.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Test, DrWatson
2+
3+
cd()
4+
5+
path = "test project"
6+
name = "lala"
7+
8+
initialize_project(path)
9+
10+
@test projectname() == path
11+
for p in DrWatson.DEFAULT_PATHS
12+
@test ispath(joinpath(path, p))
13+
end
14+
@test isfile(joinpath(path, ".gitignore"))
15+
@test isfile(joinpath(path, "README.md"))
16+
@test isfile(joinpath(path, "Project.toml"))
17+
18+
19+
@test_throws ErrorException initialize_project(path, name)
20+
21+
initialize_project(path, name; force = true, authors = ["George", "Nick"])
22+
23+
@test projectname() == name
24+
for p in DrWatson.DEFAULT_PATHS
25+
@test ispath(joinpath(path, p))
26+
end
27+
@test isfile(joinpath(path, ".gitignore"))
28+
@test isfile(joinpath(path, "README.md"))
29+
@test isfile(joinpath(path, "Project.toml"))
30+
z = read((path*"/Project.toml"), String)
31+
@test occursin("[\"George\", \"Nick\"]", z)
32+
33+
initialize_project(path, name; force = true, authors = "Sophia", git = false)
34+
z = read((path*"/Project.toml"), String)
35+
@test occursin("[\"Sophia\"]", z)
36+
37+
rm(path, recursive = true, force = true)
38+
@test !isdir(path)

test/runtests.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using DrWatson, Test
22

3-
d = (a = 0.153456453, b = 5.0, mode = "double")
4-
@test savename(d; digits = 4) == "a=0.1535_b=5_mode=double"
5-
@test savename(d, (String,)) == "mode=double"
6-
7-
rick = (never = "gonna", give = "you", up = "!");
8-
@test savename(rick) == "give=you_never=gonna_up=!"
3+
@testset "Naming" begin include("naming_tests.jl"); end
4+
@testset "Project Setup" begin include("project_tests.jl"); end

0 commit comments

Comments
 (0)