File size: 1,008 Bytes
00b8e9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import strict_rules as s
def check(t,repo,title):
 out,rem=s.clean(t,repo,title);rebuilt=[];a=b=0
 for r in rem:
  n=r['start']-a;rebuilt += [out[b:b+n],r['text']];b+=n;a=r['end']
 rebuilt.append(out[b:]);assert ''.join(rebuilt)==t
 return out,rem
x="```text\nSave as PDF\nSkip to main content\n```\n\\[x+y=3\\]\n"
assert check(x,'common-pile/libretexts_filtered','Test')[0]==x
x="Title\nSkip to main content\nLast updated\nSome content is preserved.\n"
out,rem=check(x,'common-pile/libretexts_filtered','Title')
assert 'Some content is preserved.' in out and 'Skip to main content' not in out
x='Produced by David Widger\n\n'+('Long narrative. '*150)+'\n\nEnd of Project Gutenberg\'s My Book\n'
out,rem=check(x,'common-pile/project_gutenberg_filtered','My Book')
assert 'Produced by' not in out and 'End of Project' not in out
x='```python\nprint("Grosset & Dunlap")\n```\n'
assert check(x,'common-pile/project_gutenberg_filtered','Code book')[0]==x
print('Strict removal and protected-math/code tests OK')