Skip to content

Commit

Permalink
setup Makefile for guess tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Nov 9, 2023
1 parent 729a894 commit cdb657f
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 58 deletions.
70 changes: 47 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ doc:
readme:
cargo readme --no-title > README.md

valve: valve_debug
valve: src/*.rs src/*.lalrpop
@$(MAKE) valve_debug

valve_release: src/*.rs src/*.lalrpop
rm -f valve
Expand All @@ -34,7 +35,7 @@ valve_debug: src/*.rs src/*.lalrpop
cargo build
ln -s target/debug/ontodev_valve valve

build/valve.db: test/src/table.tsv valve clean | build
build/valve.db: test/src/table.tsv clean valve | build
./valve $< $@

test/output:
Expand Down Expand Up @@ -116,47 +117,70 @@ pg_random_test: valve clean random_test_data | build test/output
@echo "Test succeeded!"

guess_test_dir = test/guess_test_data
guess_test_db = build/valve_guess.db
.PHONY: guess_test_data

$(guess_test_dir)/table1.tsv: test/generate_random_test_data.py valve $(guess_test_dir)/*.tsv
./$< $$(date +"%s") 50000 5 $(guess_test_dir)/table.tsv $(guess_test_dir)

$(guess_test_dir)/ontology:
mkdir -p $@

guess_test_data: test/generate_random_test_data.py valve valve $(guess_test_dir)/table.tsv | $(guess_test_dir)/ontology
./$< $$(date +"%s") 10000 5 $(word 3,$^) $|
guess_test_data: test/generate_random_test_data.py $(guess_test_dir)/table1.tsv valve confirm_overwrite.sh $(guess_test_dir)/*.tsv | $(guess_test_dir)/ontology
./confirm_overwrite.sh $(guess_test_dir)/ontology
rm -f $(guess_test_dir)/table1.tsv
./$< $$(date +"%s") 50000 5 $(guess_test_dir)/table.tsv $(guess_test_dir)
rm -f $(guess_test_dir)/ontology/*.tsv
./$< $$(date +"%s") 50000 5 $(guess_test_dir)/table_expected.tsv $|
rm -f $(guess_test_dir)/ontology/table1.tsv

$(guess_test_db): valve guess_test_data $(guess_test_dir)/*.tsv | build $(guess_test_dir)/ontology
rm -f $@
./$< $(guess_test_dir)/table.tsv $@

perf_test_dir = test/perf_test_data
perf_test_db = build/valve_perf.db
.PHONY: perf_test_data

$(perf_test_dir)/ontology:
mkdir -p $@

test/perf_test_data/ontology: test/generate_random_test_data.py valve test/perf_test_data/table.tsv
mkdir $@
./$< 1 10000 5 $(word 3,$^) $@
perf_test_data: test/generate_random_test_data.py valve confirm_overwrite.sh $(perf_test_dir)/*.tsv | $(perf_test_dir)/ontology
./confirm_overwrite.sh $(perf_test_dir)/ontology
rm -f $(perf_test_dir)/ontology/*.tsv
./$< $$(date +"%s") 10000 5 $(perf_test_dir)/table.tsv $|

build/valve_perf.db: valve | test/perf_test_data/ontology build
@if [ -f $@ ]; \
then \
echo "'$@' exists but is out of date. To rebuild '$@', run \`make cleanperfdb\`" \
"before running \`make $@\`" ; \
false; \
fi
time -p ./$< --verbose test/perf_test_data/table.tsv $@
$(perf_test_db): valve perf_test_data $(perf_test_dir)/*.tsv | build $(perf_test_dir)/ontology
rm -f $@
time -p ./$< --verbose $(perf_test_dir)/table.tsv $@

.PHONY: sqlite_perf_test
sqlite_perf_test: build/valve_perf.db | test/output
time -p scripts/export.py messages $< $| $(tables_to_test)

.PHONY: pg_perf_test
pg_perf_test: valve test/perf_test_data/ontology | test/output
time -p ./$< --verbose test/perf_test_data/table.tsv postgresql:///valve_postgres
pg_perf_test: valve $(perf_test_dir)/ontology | test/output
time -p ./$< --verbose $(perf_test_dir)/table.tsv postgresql:///valve_postgres
time -p scripts/export.py messages postgresql:///valve_postgres $| $(tables_to_test)

.PHONY: perf_test
perf_test: sqlite_perf_test pg_perf_test

clean:
rm -Rf build/valve.db build/valve_random.db test/output $(random_test_dir)/ontology $(guess_test_dir)/ontology
rm -Rf build/valve.db* build/valve_random.db* test/output $(random_test_dir)/ontology valve

clean_guess_db:
rm -Rf build/valve_guess.db

cleanperfdb:
clean_guess_data:
rm -Rf $(guess_test_dir)/table1.tsv $(guess_test_dir)/ontology

clean_perf_db:
rm -Rf build/valve_perf.db

cleanperfdata:
rm -Rf test/perf_test_data/ontology
clean_perf_data:
rm -Rf $(perf_test_dir)/ontology

cleanall: clean cleanperfdb cleanperfdata
cleanall: clean clean_perf_db clean_perf_data clean_guess_db clean_guess_data
cargo clean
rm -Rf valve
rm -f valve
14 changes: 14 additions & 0 deletions confirm_overwrite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

if [ -d $1 -a ! -z "$(ls -A $1)" ]
then
printf "$1 already exists and contains the following files: $(ls -A -m -w 0 $1)\nAre you sure (y/n)? "
read enter
if [ $enter = 'y' ]
then
exit 0
else
echo "Understood. Exiting with error code."
exit 1
fi
fi
2 changes: 1 addition & 1 deletion test/generate_random_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


TOKEN_LENGTH = 9
WINDOW_SIZE = 100
WINDOW_SIZE = 50


def get_special_tables(config):
Expand Down
20 changes: 0 additions & 20 deletions test/guess_test_data/column.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,3 @@ table1 prefix prefix primary
table1 base IRI unique
table1 ontology IRI empty IRI
table1 version IRI empty IRI
table2 child trimmed_line
table2 parent empty trimmed_line
table2 xyzzy empty trimmed_line
table2 foo empty integer
table2 bar empty text
table3 source prefix
table3 id CURIE unique
table3 label label primary
table3 parent empty label
table3 related empty trimmed_line
table4 foreign_column text unique
table4 other_foreign_column text unique
table4 numeric_foreign_column integer primary
table5 foo word primary
table5 bar integer
table6 child integer
table6 parent empty integer
table6 xyzzy empty integer
table6 foo empty text
table6 bar empty integer
53 changes: 53 additions & 0 deletions test/guess_test_data/column_expected.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
table column label nulltype datatype structure description
table table table_name table_name primary name of this table
table path path path to the TSV file for this table, relative to the table.tsv file
table type empty table_type type of this table, used for tables with special meanings
table description empty description a description of this table
column table table_name from(table.table) the table that this column belongs to
column column column_name the name of this column
column label empty label the human-readable label for this column
column nulltype empty datatype_name from(datatype.datatype) the datatype for NULL values in this column
column datatype datatype_name from(datatype.datatype) the datatype for this column
column structure empty trimmed_line schema information for this column
column description empty description a description of this column
datatype datatype datatype_name primary the name of this datatype
datatype parent empty datatype_name tree(datatype) the parent datatype
datatype transform empty word
datatype condition empty datatype_condition
datatype structure empty trimmed_line
datatype description empty trimmed_text
datatype SQLite type empty datatype_name
datatype PostgreSQL type empty datatype_name
datatype RDF type empty datatype_name
datatype HTML type empty datatype_name
rule table table_name
rule when column column_name
rule when condition datatype_condition
rule then column column_name
rule then condition datatype_condition
rule level word
rule description empty description
table1 prefix prefix primary
table1 base IRI unique
table1 ontology IRI empty IRI
table1 version IRI empty IRI
table2 child trimmed_line from(table4.other_foreign_column)
table2 parent empty trimmed_line tree(child)
table2 xyzzy empty trimmed_line under(table2.child, d)
table2 foo empty integer from(table4.numeric_foreign_column)
table2 bar empty text
table3 source prefix from(table1.prefix)
table3 id CURIE unique
table3 label label primary
table3 parent empty label tree(label)
table3 related empty trimmed_line
table4 foreign_column text unique
table4 other_foreign_column text unique
table4 numeric_foreign_column integer primary
table5 foo word primary
table5 bar integer
table6 child integer from(table4.numeric_foreign_column)
table6 parent empty integer tree(child)
table6 xyzzy empty integer under(table6.child, 4)
table6 foo empty text
table6 bar empty integer
9 changes: 1 addition & 8 deletions test/guess_test_data/rule.tsv
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
table when column when condition then column then condition level description
table2 foo null bar null error bar must be null whenever foo is null
table2 foo not null bar not null error bar cannot be null if foo is not null
table2 foo IRI bar label error bar must be a label if foo is an IRI
table2 foo equals(5) bar in('y', 'z') error bar must be 'y' or 'z' if foo = 5
table6 foo null bar null error bar must be null whenever foo is null
table6 foo not null bar not null error bar cannot be null if foo is not null
table6 foo IRI bar label error bar must be a label if foo is an IRI
table6 foo equals(e) bar in(25, 26) error bar must be 25 or 26 if foo = 'e'
table1 ontology IRI null version IRI null error 'version IRI' must be null whenever 'ontology IRI' is null
7 changes: 1 addition & 6 deletions test/guess_test_data/table.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@ column test/guess_test_data/column.tsv Columns for all of the tables. column
datatype test/guess_test_data/datatype.tsv Datatypes for all of the columns datatype
rule test/guess_test_data/rule.tsv More complex "when" rules rule
table test/guess_test_data/table.tsv All of the user-editable tables in this project. table
table1 test/guess_test_data/ontology/table1.tsv The first data table
table2 test/guess_test_data/ontology/table2.tsv The second data table
table3 test/guess_test_data/ontology/table3.tsv The third data table
table4 test/guess_test_data/ontology/table4.tsv The fourth data table
table5 test/guess_test_data/ontology/table5.tsv The fifth data table
table6 test/guess_test_data/ontology/table6.tsv The sixth data table (like table2 but all numeric)
table1 test/guess_test_data/table1.tsv The first data table
11 changes: 11 additions & 0 deletions test/guess_test_data/table_expected.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table path description type
column test/guess_test_data/column_expected.tsv Columns for all of the tables. column
datatype test/guess_test_data/datatype.tsv Datatypes for all of the columns datatype
rule test/guess_test_data/rule.tsv More complex "when" rules rule
table test/guess_test_data/table_expected.tsv All of the user-editable tables in this project. table
table1 test/guess_test_data/table1.tsv The first data table
table2 test/guess_test_data/ontology/table2.tsv The second data table
table3 test/guess_test_data/ontology/table3.tsv The third data table
table4 test/guess_test_data/ontology/table4.tsv The fourth data table
table5 test/guess_test_data/ontology/table5.tsv The fifth data table
table6 test/guess_test_data/ontology/table6.tsv The sixth data table (like table2 but all numeric)

0 comments on commit cdb657f

Please sign in to comment.