Skip to content

Commit

Permalink
Test to check that sector{,imp}list.txt are deduplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberiaResurrection committed Jan 12, 2025
1 parent 23c06ab commit 01b383e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Tests/testUniqueSectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Created on Jan 12, 2025
@author: CyberiaResurrection
"""
import codecs
import os
import tempfile

from Tests.baseTest import baseTest
from pytest_console_scripts import ScriptRunner


class testUniqueSectors(baseTest):

def testSectorListIsUnique(self):
fullpath = self.unpack_filename('../PyRoute/unique_sectors.py')

cases = [
("sectorlist.txt", "../sectorlist.txt"),
("sectorimplist.txt", "../sectorimplist.txt")
]

for filename, fullname in cases:
with self.subTest(filename):
outfile = tempfile.NamedTemporaryFile(mode="w", encoding="utf-8")
srcfile = os.path.abspath(fullname)

cwd = os.getcwd()
runner = ScriptRunner(launch_mode="subprocess", rootdir=cwd, print_result=False)

foo = runner.run([fullpath, "--infile", srcfile, "--outfile", outfile.name])
self.assertEqual(0, foo.returncode, "unique_sectors did not complete successfully: " + foo.stderr)

inlines = []
with codecs.open(srcfile, 'r', 'utf-8') as infile:
inlines = [line for line in infile]

outlines = []
with codecs.open(outfile.name, 'r', 'utf-8') as outfile:
outlines = [line for line in outfile]
outfile.close()

self.assertEqual(len(outlines), len(inlines), filename + " has at least one duplicate")

0 comments on commit 01b383e

Please sign in to comment.