Skip to content

Commit d20d040

Browse files
authored
Add tests
1 parent 2965a0b commit d20d040

6 files changed

Lines changed: 248 additions & 2 deletions

File tree

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# We use Ubuntu as base image
2-
FROM ubuntu
2+
FROM ubuntu:18.04
33

44
WORKDIR /app
55

@@ -36,6 +36,7 @@ RUN git clone https://github.com/python-pillow/Pillow.git \
3636
&& python3 setup.py build_ext --enable-freetype install
3737

3838
RUN python3 setup.py install
39-
RUN pip3 install -r requirements-hw.txt
39+
RUN pip3 install -r requirements.txt
40+
RUN pip3 install pytest
4041
RUN pip3 install codecov
4142

tests.py

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,236 @@ def test_generate_data_with_word_split(self):
761761

762762
os.remove("tests/out/TEST TEST TEST_14.png")
763763

764+
def test_generate_data_with_first_name_format(self):
765+
FakeTextDataGenerator.generate(
766+
15,
767+
"TEST TEST TEST",
768+
"tests/font.ttf",
769+
"tests/out/",
770+
64,
771+
"png",
772+
0,
773+
False,
774+
0,
775+
False,
776+
1,
777+
0,
778+
0,
779+
False,
780+
0,
781+
-1,
782+
0,
783+
"#010101",
784+
0,
785+
1,
786+
0,
787+
(5, 5, 5, 5),
788+
0,
789+
0,
790+
True,
791+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
792+
)
793+
794+
self.assertTrue(
795+
diff(
796+
"tests/out/TEST TEST TEST_15.png",
797+
"tests/expected_results/TEST TEST TEST_15.png",
798+
delete_diff_file=True,
799+
)
800+
< 0.01
801+
)
802+
803+
os.remove("tests/out/TEST TEST TEST_15.png")
804+
805+
def test_generate_data_with_second_name_format(self):
806+
FakeTextDataGenerator.generate(
807+
16,
808+
"TEST TEST TEST",
809+
"tests/font.ttf",
810+
"tests/out/",
811+
64,
812+
"png",
813+
0,
814+
False,
815+
0,
816+
False,
817+
1,
818+
0,
819+
0,
820+
False,
821+
1,
822+
-1,
823+
0,
824+
"#010101",
825+
0,
826+
1,
827+
0,
828+
(5, 5, 5, 5),
829+
0,
830+
0,
831+
True,
832+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
833+
)
834+
835+
self.assertTrue(
836+
diff(
837+
"tests/out/16_TEST TEST TEST.png",
838+
"tests/expected_results/16_TEST TEST TEST.png",
839+
delete_diff_file=True,
840+
)
841+
< 0.01
842+
)
843+
844+
os.remove("tests/out/16_TEST TEST TEST.png")
845+
846+
def test_generate_data_with_third_name_format(self):
847+
FakeTextDataGenerator.generate(
848+
17,
849+
"TEST TEST TEST",
850+
"tests/font.ttf",
851+
"tests/out/",
852+
64,
853+
"png",
854+
0,
855+
False,
856+
0,
857+
False,
858+
1,
859+
0,
860+
0,
861+
False,
862+
2,
863+
-1,
864+
0,
865+
"#010101",
866+
0,
867+
1,
868+
0,
869+
(5, 5, 5, 5),
870+
0,
871+
0,
872+
True,
873+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
874+
)
875+
876+
self.assertTrue(
877+
diff(
878+
"tests/out/17.png",
879+
"tests/expected_results/17.png",
880+
delete_diff_file=True,
881+
)
882+
< 0.01
883+
)
884+
885+
os.remove("tests/out/17.png")
886+
887+
def test_generate_data_with_wrong_name_format(self):
888+
FakeTextDataGenerator.generate(
889+
18,
890+
"TEST TEST TEST",
891+
"tests/font.ttf",
892+
"tests/out/",
893+
64,
894+
"png",
895+
0,
896+
False,
897+
0,
898+
False,
899+
1,
900+
0,
901+
0,
902+
False,
903+
3,
904+
-1,
905+
0,
906+
"#010101",
907+
0,
908+
1,
909+
0,
910+
(5, 5, 5, 5),
911+
0,
912+
0,
913+
True,
914+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
915+
)
916+
917+
self.assertTrue(
918+
diff(
919+
"tests/out/TEST TEST TEST_18.png",
920+
"tests/expected_results/TEST TEST TEST_18.png",
921+
delete_diff_file=True,
922+
)
923+
< 0.01
924+
)
925+
926+
os.remove("tests/out/TEST TEST TEST_18.png")
927+
928+
def test_generate_data_with_quasicrystal_background_from_generate(self):
929+
FakeTextDataGenerator.generate(
930+
19,
931+
"TEST TEST TEST",
932+
"tests/font.ttf",
933+
"tests/out/",
934+
64,
935+
"png",
936+
0,
937+
False,
938+
0,
939+
False,
940+
2,
941+
0,
942+
0,
943+
False,
944+
0,
945+
-1,
946+
0,
947+
"#010101",
948+
0,
949+
1,
950+
0,
951+
(5, 5, 5, 5),
952+
0,
953+
0,
954+
True,
955+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
956+
)
957+
958+
os.remove("tests/out/TEST TEST TEST_19.png")
959+
960+
def test_raise_if_invalid_orientation(self):
961+
try:
962+
FakeTextDataGenerator.generate(
963+
20,
964+
"TEST TEST TEST",
965+
"tests/font.ttf",
966+
"tests/out/",
967+
64,
968+
"jpg",
969+
0,
970+
False,
971+
0,
972+
False,
973+
1,
974+
0,
975+
0,
976+
False,
977+
0,
978+
1000,
979+
2,
980+
"#010101",
981+
3,
982+
1,
983+
0,
984+
(5, 5, 5, 5),
985+
0,
986+
0,
987+
False,
988+
os.path.join(os.path.split(os.path.realpath(__file__))[0], "trdg/images"),
989+
)
990+
raise Exception("Invalid orientation did not throw")
991+
except ValueError:
992+
pass
993+
764994
def test_generate_string_with_letters(self):
765995
s = create_strings_randomly(1, False, 1, True, False, False, "en")[0]
766996

@@ -1058,6 +1288,21 @@ def test_personaldict_unlocated(self):
10581288
self.assertTrue(len(os.listdir("tests/out/")) == 0)
10591289
empty_directory("tests/out/")
10601290

1291+
def test_first_name_format(self):
1292+
args = [
1293+
"python3",
1294+
"run.py",
1295+
"--dict",
1296+
"dicts/unlocatedDict.txt",
1297+
"-c",
1298+
"1",
1299+
"--output_dir",
1300+
"../tests/out/",
1301+
]
1302+
subprocess.Popen(args, cwd="trdg/").wait()
1303+
self.assertTrue(len(os.listdir("tests/out/")) == 0)
1304+
empty_directory("tests/out/")
1305+
10611306

10621307
# def test_word_count(self):
10631308
# args = ['python3', 'run.py', '-c', '1', '-w', '5']
6.49 KB
Loading

tests/expected_results/17.png

6.49 KB
Loading
6.49 KB
Loading
6.49 KB
Loading

0 commit comments

Comments
 (0)