Skip to content

Commit 9009636

Browse files
committed
Added tests for the --copy-all flag
1 parent 3269230 commit 9009636

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

tests/__snapshots__/test_stuff.ambr

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,35 @@
1818
True,
1919
])
2020
# ---
21+
# name: test_copyAllFiles
22+
list([
23+
'blankDir/',
24+
' index.html',
25+
' myRack.html',
26+
' bonescrawlhome.html',
27+
' bonesrunhome.html',
28+
' bonesboundhome.html',
29+
' report.html',
30+
' template.html',
31+
' bonescallhome.html',
32+
' 404.html',
33+
' robots.txt',
34+
' emacsFiles.html',
35+
' Power7.html',
36+
' contact.html',
37+
' static/',
38+
' theDreadedTexFile.tex',
39+
' styles.css',
40+
' favicon.ico',
41+
' theIdioticTimeDistributionOfAReport.pdf',
42+
' js/',
43+
' preloadImages.js',
44+
' minimal-theme-switcher.js',
45+
' anotherThemeChanger.js',
46+
])
47+
# ---
2148
# name: test_dir
22-
Namespace(dir=True, inputFile=['dir'], templates_dir=None, output='.', no_warnings=False, verbose=False)
49+
Namespace(dir=True, inputFile=['dir'], templates_dir=None, output='.', no_warnings=False, verbose=False, copy_all=False)
2350
# ---
2451
# name: test_getIncludeFileText
2552
tuple(
@@ -30,7 +57,7 @@
3057
)
3158
# ---
3259
# name: test_infile
33-
Namespace(dir=False, inputFile=['inputFile'], templates_dir=None, output='.', no_warnings=False, verbose=False)
60+
Namespace(dir=False, inputFile=['inputFile'], templates_dir=None, output='.', no_warnings=False, verbose=False, copy_all=False)
3461
# ---
3562
# name: test_lookForInclude
3663
tuple(
@@ -111,17 +138,17 @@
111138
)
112139
# ---
113140
# name: test_templates_dir
114-
Namespace(dir=True, inputFile=['dir'], templates_dir=['templates'], output='.', no_warnings=False, verbose=False)
141+
Namespace(dir=True, inputFile=['dir'], templates_dir=['templates'], output='.', no_warnings=False, verbose=False, copy_all=False)
115142
# ---
116143
# name: test_templates_infile
117-
Namespace(dir=False, inputFile=['inputFile'], templates_dir=['template'], output='.', no_warnings=False, verbose=False)
144+
Namespace(dir=False, inputFile=['inputFile'], templates_dir=['template'], output='.', no_warnings=False, verbose=False, copy_all=False)
118145
# ---
119146
# name: test_templates_output_dir
120-
Namespace(dir=True, inputFile=['dir'], templates_dir=['templates'], output=['output'], no_warnings=False, verbose=False)
147+
Namespace(dir=True, inputFile=['dir'], templates_dir=['templates'], output=['output'], no_warnings=False, verbose=False, copy_all=False)
121148
# ---
122149
# name: test_templates_output_infile
123-
Namespace(dir=False, inputFile=['inputFile'], templates_dir=['template'], output=['output'], no_warnings=False, verbose=False)
150+
Namespace(dir=False, inputFile=['inputFile'], templates_dir=['template'], output=['output'], no_warnings=False, verbose=False, copy_all=False)
124151
# ---
125152
# name: test_verbose
126-
Namespace(dir=False, inputFile=['inputFile'], templates_dir=None, output='.', no_warnings=False, verbose=True)
153+
Namespace(dir=False, inputFile=['inputFile'], templates_dir=None, output='.', no_warnings=False, verbose=True, copy_all=False)
127154
# ---

tests/test_stuff.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import filecmp
77
import pytest
88
from pathlib import Path
9+
import os
10+
import shutil
911

1012

1113
def test_verbose(snapshot):
@@ -90,7 +92,25 @@ def test_checkFiles(snapshot):
9092
arrayOfMatchesOfNot.append(filecmp.cmp(sitesFile, knownGoodFile, shallow=False))
9193
assert arrayOfMatchesOfNot == snapshot
9294

93-
# def test_checkFiles(snapshot):
95+
96+
def test_copyAllFiles(snapshot):
97+
if(os.path.exists("tests/testFolder/blankDir")):
98+
if os.path.isfile("tests/testFolder/blankDir"):
99+
os.remove("tests/testFolder/blankDir")
100+
else:
101+
shutil.rmtree("tests/testFolder/blankDir")
102+
ssri.copyAllFiles("tests/testFolder/staging","tests/testFolder/blankDir")
103+
outputCheck = []
104+
for root, dirs, files in os.walk("tests/testFolder/blankDir"): # Gratefully borrowed from here https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python
105+
level = root.replace("tests/testFolder/blankDir", '').count(os.sep) # As dir structure is important to track if it changes in this test so formatting the output makes sense
106+
indent = ' ' * 4 * (level)
107+
outputCheck.append(('{}{}/'.format(indent, os.path.basename(root))))
108+
subindent = ' ' * 4 * (level + 1)
109+
for f in files:
110+
outputCheck.append(('{}{}'.format(subindent, f)))
111+
shutil.rmtree("tests/testFolder/blankDir")
112+
assert outputCheck == snapshot
113+
94114
# inputFiles = ssri.getListOfFilesToSearchDir("tests/testFolder/staging", ["tests/testFolder/sites"], True, False)
95115
# knownGoodFiles = ssri.getListOfFilesToSearchDir("tests/testFolder/staging", ["tests/testFolder/sites"], True, False) # This is me being lazy and using getListOfFiles to get an array for the known good copy of sites
96116
# fileCreatedCounter = 0

0 commit comments

Comments
 (0)