-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create fake data and use it on the tests
Create a debug folder with a Debug module and a Data module. The Data module includes fake data for a variety of situations. This data is used in the tests now. Closes #375
- Loading branch information
1 parent
9d9d8bd
commit b1114d0
Showing
6 changed files
with
93 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ using YAML: YAML | |
|
||
include("Copier.jl") | ||
include("api.jl") | ||
include("debug/Debug.jl") | ||
include("guess.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Fake data for testing | ||
- `Debug.Data`: NamedTuple of Dictionaries with default data | ||
- `Debug.Data.minimum_defaults`: Required data if you use `defaults = true` | ||
- `Debug.Data.strategy_minimum`: Required data for strategy minimum, no defaults. | ||
- `Debug.Data.strategy_recommended`: Required data for strategy recommended, no defaults. | ||
- `Debug.Data.strategy_ask`: Required data for strategy ask, no defaults. | ||
""" | ||
module Data | ||
|
||
using Random: MersenneTwister | ||
using UUIDs: uuid4 | ||
|
||
const minimum_defaults = Dict( | ||
"PackageName" => "FakePkg", | ||
"PackageUUID" => string(uuid4(MersenneTwister(123))), | ||
"PackageOwner" => "bestietemplate", | ||
"AuthorName" => "Bestie Template", | ||
"AuthorEmail" => "[email protected]", | ||
) | ||
|
||
const strategy_minimum = merge( | ||
minimum_defaults, | ||
Dict( | ||
"JuliaMinVersion" => "1.6", | ||
"License" => "MIT", | ||
"Indentation" => "2", | ||
"AnswerStrategy" => "minimum", | ||
), | ||
) | ||
|
||
const strategy_recommended = merge(strategy_minimum, Dict("AnswerStrategy" => "recommended")) | ||
|
||
const strategy_ask = merge( | ||
strategy_recommended, | ||
Dict( | ||
"AnswerStrategy" => "ask", | ||
"AddPrecommit" => true, | ||
"AddMacToCI" => true, | ||
"AddWinToCI" => true, | ||
"RunJuliaNightlyOnCI" => true, | ||
"UseCirrusCI" => false, | ||
"AddCopierCI" => false, | ||
"AddContributionDocs" => true, | ||
"AddAllcontributors" => true, | ||
"AddCodeOfConduct" => true, | ||
"AddGitHubTemplates" => true, | ||
), | ||
) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Module Debug | ||
Tools for debugging Bestie. Nothing here is public API. | ||
Noteworthy: [`BestieTemplate.Debug.Data`](@ref) | ||
""" | ||
module Debug | ||
|
||
include("Data.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,42 +15,12 @@ if get(ENV, "CI", "nothing") == "nothing" | |
end | ||
|
||
using BestieTemplate | ||
using BestieTemplate.Debug.Data: Data | ||
using Pkg | ||
using PythonCall | ||
using Test | ||
using YAML | ||
|
||
template_minimum_options = Dict( | ||
"PackageName" => "Tmp", | ||
"PackageUUID" => "1234", | ||
"PackageOwner" => "test", | ||
"AuthorName" => "Test", | ||
"AuthorEmail" => "[email protected]", | ||
) | ||
|
||
template_options = Dict( | ||
"PackageName" => "Tmp", | ||
"PackageUUID" => "1234", | ||
"PackageOwner" => "test", | ||
"AuthorName" => "Test", | ||
"AuthorEmail" => "[email protected]", | ||
"AskAdvancedQuestions" => true, | ||
"AddAllcontributors" => true, | ||
"JuliaMinVersion" => "1.6", | ||
"License" => "MIT", | ||
"AddCodeOfConduct" => true, | ||
"Indentation" => "3", | ||
"AddMacToCI" => true, | ||
"AddWinToCI" => true, | ||
"RunJuliaNightlyOnCI" => true, | ||
"AddContributionDocs" => true, | ||
"UseCirrusCI" => false, | ||
"AddPrecommit" => true, | ||
"AddGitHubTemplates" => true, | ||
"AnswerStrategy" => "ask", | ||
"AddCopierCI" => false, | ||
) | ||
|
||
function _git_setup() | ||
run(`git init`) | ||
run(`git add .`) | ||
|
@@ -82,8 +52,10 @@ function test_diff_dir(dir1, dir2) | |
end | ||
end | ||
|
||
min_bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_minimum_options]...) | ||
bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...) | ||
data_to_cli_args(dict) = vcat([["-d"; "$k=$v"] for (k, v) in dict]...) | ||
cli_args_min_defaults = data_to_cli_args(Data.minimum_defaults) | ||
cli_args_strat_ask = data_to_cli_args(Data.strategy_ask) | ||
|
||
template_path = joinpath(@__DIR__, "..") | ||
template_url = "https://github.com/abelsiqueira/BestieTemplate.jl" | ||
|
||
|
@@ -94,24 +66,24 @@ end | |
|
||
@testset "Compare BestieTemplate.generate vs copier CLI on URL/main" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --vcs-ref main --quiet $bash_args $template_url $dir_copier_cli`) | ||
run(`copier copy --vcs-ref main --quiet $cli_args_strat_ask $template_url $dir_copier_cli`) | ||
|
||
mktempdir(TMPDIR; prefix = "copy_") do tmpdir | ||
BestieTemplate.generate(tmpdir, template_options; quiet = true, vcs_ref = "main") | ||
BestieTemplate.generate(tmpdir, Data.strategy_ask; quiet = true, vcs_ref = "main") | ||
test_diff_dir(tmpdir, dir_copier_cli) | ||
end | ||
end | ||
end | ||
|
||
@testset "Compare BestieTemplate.generate vs copier CLI on HEAD" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`) | ||
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_path $dir_copier_cli`) | ||
|
||
mktempdir(TMPDIR; prefix = "copy_") do tmpdir | ||
BestieTemplate.generate( | ||
template_path, | ||
tmpdir, | ||
template_options; | ||
Data.strategy_ask; | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
) | ||
|
@@ -122,17 +94,17 @@ end | |
|
||
@testset "Compare BestieTemplate.update vs copier CLI update" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --defaults --quiet $min_bash_args $template_url $dir_copier_cli`) | ||
run(`copier copy --defaults --quiet $cli_args_min_defaults $template_url $dir_copier_cli`) | ||
cd(dir_copier_cli) do | ||
_git_setup() | ||
end | ||
run(`copier update --defaults --quiet $bash_args $dir_copier_cli`) | ||
run(`copier update --defaults --quiet $cli_args_strat_ask $dir_copier_cli`) | ||
|
||
mktempdir(TMPDIR; prefix = "update_") do tmpdir | ||
BestieTemplate.generate(tmpdir, template_minimum_options; defaults = true, quiet = true) | ||
BestieTemplate.generate(tmpdir, Data.minimum_defaults; defaults = true, quiet = true) | ||
cd(tmpdir) do | ||
_git_setup() | ||
BestieTemplate.update(template_options; defaults = true, quiet = true) | ||
BestieTemplate.update(Data.strategy_ask; defaults = true, quiet = true) | ||
end | ||
|
||
test_diff_dir(tmpdir, dir_copier_cli) | ||
|
@@ -142,7 +114,7 @@ end | |
|
||
@testset "Test that BestieTemplate.generate warns and exits for existing copy" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_url $dir_copier_cli`) | ||
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_url $dir_copier_cli`) | ||
cd(dir_copier_cli) do | ||
_git_setup() | ||
end | ||
|
@@ -169,7 +141,7 @@ end | |
BestieTemplate.generate( | ||
template_path, | ||
".", | ||
template_options; | ||
Data.strategy_ask; | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
) | ||
|
@@ -182,7 +154,7 @@ end | |
BestieTemplate.generate( | ||
template_path, | ||
"some_folder3", | ||
template_options; | ||
Data.strategy_ask; | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
) | ||
|
@@ -193,21 +165,23 @@ end | |
|
||
@testset "Testing copy, recopy and rebase" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`) | ||
run(`copier copy --vcs-ref HEAD --quiet $cli_args_strat_ask $template_path $dir_copier_cli`) | ||
|
||
@testset "Compare copied project vs copier CLI baseline" begin | ||
mktempdir(TMPDIR; prefix = "copy_") do tmpdir | ||
BestieTemplate.Copier.copy(tmpdir, template_options; quiet = true, vcs_ref = "HEAD") | ||
BestieTemplate.Copier.copy(tmpdir, Data.strategy_ask; quiet = true, vcs_ref = "HEAD") | ||
test_diff_dir(tmpdir, dir_copier_cli) | ||
end | ||
end | ||
|
||
@testset "Compare recopied project vs copier CLI baseline" begin | ||
mktempdir(TMPDIR; prefix = "recopy_") do tmpdir | ||
run(`copier copy --vcs-ref HEAD --defaults --quiet $min_bash_args $template_path $tmpdir`) | ||
run( | ||
`copier copy --vcs-ref HEAD --defaults --quiet $cli_args_min_defaults $template_path $tmpdir`, | ||
) | ||
BestieTemplate.Copier.recopy( | ||
tmpdir, | ||
template_options; | ||
Data.strategy_ask; | ||
quiet = true, | ||
overwrite = true, | ||
vcs_ref = "HEAD", | ||
|
@@ -218,7 +192,7 @@ end | |
|
||
@testset "Compare updated project vs copier CLI baseline" begin | ||
mktempdir(TMPDIR; prefix = "update_") do tmpdir | ||
run(`copier copy --defaults --quiet $min_bash_args $template_path $tmpdir`) | ||
run(`copier copy --defaults --quiet $cli_args_min_defaults $template_path $tmpdir`) | ||
cd(tmpdir) do | ||
run(`git init`) | ||
run(`git add .`) | ||
|
@@ -228,7 +202,7 @@ end | |
end | ||
BestieTemplate.Copier.update( | ||
tmpdir, | ||
template_options; | ||
Data.strategy_ask; | ||
overwrite = true, | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
|
@@ -265,7 +239,7 @@ end | |
@testset "Test automatic guessing the package name from the path" begin | ||
mktempdir(TMPDIR; prefix = "path_is_dir_") do dir_path_is_dir | ||
cd(dir_path_is_dir) do | ||
data = Dict(key => value for (key, value) in template_options if key != "PackageName") | ||
data = Dict(key => value for (key, value) in Data.strategy_ask if key != "PackageName") | ||
mkdir("some_folder") | ||
BestieTemplate.generate( | ||
template_path, | ||
|
@@ -293,7 +267,7 @@ end | |
mktempdir(TMPDIR; prefix = "valid_pkg_name_") do dir | ||
cd(dir) do | ||
for name in ["Bad.jl", "0Bad", "bad"] | ||
data = copy(template_options) | ||
data = copy(Data.strategy_ask) | ||
data["PackageName"] = name | ||
@test_throws PythonCall.Core.PyException BestieTemplate.generate( | ||
template_path, | ||
|