def setUp(self): """ Initialize some vars we'll need on every test. FT format is not especially structured, so not a lot of work to do here. """ self.modfile = ModFile(0) self.df = io.StringIO()
def setUp(self): """ Initialize some vars we'll need on every test. """ self.modfile = ModFile(0) self.modfile.full_filename = 'modname.txt' self.df = io.StringIO()
def test_after_ascii_art_no_whitespace_or_comments(self): for char in ['_', '\\', '.', ':', '|', '~']: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line('testing') self.modfile.add_comment_line(char) self.assertEqual(self.modfile.mod_desc, ['testing', char])
def setUp(self): """ Initialize some vars we'll need on every test. We're fudging the BLCMM file format a bit here, which shouldn't matter 'cause our code doesn't actually look for any of that stuff. """ self.modfile = ModFile(0) self.df = io.StringIO() print(' <head>', file=self.df) print(' <type name="BL2" offline="false"/>', file=self.df) print(' <profiles>', file=self.df) print(' <profile name="default" current="true"/>', file=self.df) print(' </profiles>', file=self.df) print(' </head>', file=self.df) print(' <body>', file=self.df)
def test_categories_updated(self): for (initial_status, end_status) in [ (ModFile.S_UNKNOWN, ModFile.S_UPDATED), (ModFile.S_CACHED, ModFile.S_UPDATED), (ModFile.S_NEW, ModFile.S_NEW), (ModFile.S_UPDATED, ModFile.S_UPDATED), ]: with self.subTest(initial_status=initial_status): modfile = ModFile(0, initial_status=initial_status) self.assertFalse(modfile.seen) self.assertEqual(list(modfile.categories), []) self.assertEqual(modfile.status, initial_status) modfile.set_categories(['cat1']) self.assertTrue(modfile.seen) self.assertEqual(list(modfile.categories), ['cat1']) self.assertEqual(modfile.status, end_status)
def test_readme_updated(self): for (initial_status, end_status) in [ (ModFile.S_UNKNOWN, ModFile.S_UPDATED), (ModFile.S_CACHED, ModFile.S_UPDATED), (ModFile.S_NEW, ModFile.S_NEW), (ModFile.S_UPDATED, ModFile.S_UPDATED), ]: with self.subTest(initial_status=initial_status): modfile = ModFile(0, initial_status=initial_status) self.assertFalse(modfile.seen) self.assertEqual(modfile.readme_desc, []) self.assertEqual(modfile.status, initial_status) modfile.update_readme_desc(['readme']) self.assertTrue(modfile.seen) self.assertEqual(modfile.readme_desc, ['readme']) self.assertEqual(modfile.status, end_status)
def test_unknown(self): # Obviously fudging the format a bit, whatever. self.make_file('filename', [ '# Filename!', 'Testing Mod', ]) mf = ModFile(0, dirinfo=self.dirinfo, filename='filename') self.assertEqual(mf.seen, True) self.assertEqual(mf.mod_title, 'Filename!') self.assertEqual(mf.mod_desc, ['Testing Mod'])
def test_urls_unchanged_empty(self): for (initial_status, end_status) in [ (ModFile.S_UNKNOWN, ModFile.S_UNKNOWN), (ModFile.S_CACHED, ModFile.S_CACHED), (ModFile.S_NEW, ModFile.S_NEW), (ModFile.S_UPDATED, ModFile.S_UPDATED), ]: with self.subTest(initial_status=initial_status): modfile = ModFile(0, initial_status=initial_status) self.assertFalse(modfile.seen) self.assertIsNone(modfile.nexus_link) self.assertEqual(list(modfile.screenshots), []) self.assertEqual(modfile.status, initial_status) modfile.set_urls([]) self.assertTrue(modfile.seen) self.assertIsNone(modfile.nexus_link) self.assertEqual(list(modfile.screenshots), []) self.assertEqual(modfile.status, end_status)
def test_urls_updated_screenshot(self): screen_url = 'https://imgur.com/whatever' for (initial_status, end_status) in [ (ModFile.S_UNKNOWN, ModFile.S_UPDATED), (ModFile.S_CACHED, ModFile.S_UPDATED), (ModFile.S_NEW, ModFile.S_NEW), (ModFile.S_UPDATED, ModFile.S_UPDATED), ]: with self.subTest(initial_status=initial_status): modfile = ModFile(0, initial_status=initial_status) self.assertFalse(modfile.seen) self.assertIsNone(modfile.nexus_link) self.assertEqual(list(modfile.screenshots), []) self.assertEqual(modfile.status, initial_status) modfile.set_urls([screen_url]) self.assertTrue(modfile.seen) self.assertIsNone(modfile.nexus_link) self.assertEqual(list(modfile.screenshots), [screen_url]) self.assertEqual(modfile.status, end_status)
def test_blank_first_line(self): # Obviously fudging the format a bit, whatever. self.make_file('filename', [ '', '#<Mod Name>', 'Testing Mod', '#</Mod Name>', ]) mf = ModFile(0, dirinfo=self.dirinfo, filename='filename') self.assertEqual(mf.seen, True) self.assertEqual(mf.mod_title, 'Mod Name') self.assertEqual(mf.mod_desc, ['Testing Mod'])
def test_blcmm(self): # Obviously fudging the format a bit, whatever. self.make_file('filename', [ '<BLCMM v="1">', '<category name="Mod Name">', '<comment>Testing Mod</comment>', '</category>', '</BLCMM>', ]) mf = ModFile(0, dirinfo=self.dirinfo, filename='filename') self.assertEqual(mf.seen, True) self.assertEqual(mf.mod_title, 'Mod Name') self.assertEqual(mf.mod_desc, ['Testing Mod'])
def test_urls_unchanged_nexus(self): nexus_url = 'https://nexusmods.com/borderlands/whatever' for (initial_status, end_status) in [ (ModFile.S_UNKNOWN, ModFile.S_UNKNOWN), (ModFile.S_CACHED, ModFile.S_CACHED), (ModFile.S_NEW, ModFile.S_NEW), (ModFile.S_UPDATED, ModFile.S_UPDATED), ]: with self.subTest(initial_status=initial_status): modfile = ModFile(0, initial_status=initial_status) modfile.nexus_link = nexus_url self.assertFalse(modfile.seen) self.assertEqual(modfile.nexus_link, nexus_url) self.assertEqual(list(modfile.screenshots), []) self.assertEqual(modfile.status, initial_status) modfile.set_urls([nexus_url]) self.assertTrue(modfile.seen) self.assertEqual(modfile.nexus_link, nexus_url) self.assertEqual(list(modfile.screenshots), []) self.assertEqual(modfile.status, end_status)
def test_blank_first_two_lines(self): # This should actually end up getting classified as an Unknown file, # at the moment. self.make_file('filename', [ '', '', '#<Mod Name>', 'Testing Mod', '#</Mod Name>', ]) mf = ModFile(0, dirinfo=self.dirinfo, filename='filename') self.assertEqual(mf.seen, True) self.assertEqual(mf.mod_title, 'filename') self.assertEqual(mf.mod_desc, ['<Mod Name>', 'Testing Mod', '</Mod Name>'])
class ModFileBLCMMTests(unittest.TestCase): """ Testing importing a BLCMM-formatted file """ def setUp(self): """ Initialize some vars we'll need on every test. We're fudging the BLCMM file format a bit here, which shouldn't matter 'cause our code doesn't actually look for any of that stuff. """ self.modfile = ModFile(0) self.df = io.StringIO() print(' <head>', file=self.df) print(' <type name="BL2" offline="false"/>', file=self.df) print(' <profiles>', file=self.df) print(' <profile name="default" current="true"/>', file=self.df) print(' </profiles>', file=self.df) print(' </head>', file=self.df) print(' <body>', file=self.df) def set_df_contents(self, cat_name, lines): """ Sets the contents of the "file" that we're gonna read in """ print(' <category name="{}">'.format(cat_name), file=self.df) for line in lines: print(line, file=self.df) print(' </category>', file=self.df) print(' </body>', file=self.df) print('</BLCMM>', file=self.df) print('', file=self.df) print('#Commands:', file=self.df) print('set foo bar baz', file=self.df) self.df.seek(0) def test_load_commentless(self): self.set_df_contents('Mod Name', [ '<category name="Test">', '</category>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_title, 'Mod Name') self.assertEqual(self.modfile.mod_desc, []) def test_single_comment(self): self.set_df_contents('Mod Name', [ '<comment>Testing</comment>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_two_comments(self): self.set_df_contents('Mod Name', [ '<comment>Testing</comment>', '<comment>Testing 2</comment>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing', 'Testing 2']) def test_two_comments_interrupted(self): self.set_df_contents('Mod Name', [ '<comment>Testing</comment>', '<code profiles="default">set foo bar baz</code>', '<comment>Testing 2</comment>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_single_comment_inner_category(self): self.set_df_contents('Mod Name', [ '<category name="Test">', '<comment>Testing</comment>', '</category>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_single_comment_inner_category_2deep(self): self.set_df_contents('Mod Name', [ '<category name="Test">', '<category name="Test2">', '<comment>Testing</comment>', '</category>', '</category>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_single_comment_inner_category_after_set(self): self.set_df_contents('Mod Name', [ '<category name="Test">', '<code profiles="default">set foo bar baz</code>', '<comment>Testing</comment>', '</category>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_two_comments_inner_category_after_set_interrupted(self): self.set_df_contents('Mod Name', [ '<category name="Test">', '<code profiles="default">set foo bar baz</code>', '<comment>Testing</comment>', '<code profiles="default">set foo bar baz</code>', '<comment>Testing 2</comment>', '</category>', ]) self.modfile.load_blcmm(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing'])
def test_initial_ascii_art(self): for char in ['_', '/', '\\', '.', ':', '|', '#', '~', ' ', "\t"]: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line(char) self.assertEqual(self.modfile.mod_desc, [])
def test_strips(self): for char in ['/', '#', ' ', "\n", "\r", "\t"]: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line('{}testing{}'.format(char, char)) self.assertEqual(self.modfile.mod_desc, ['testing'])
def setUp(self): """ Initialize some vars we'll need on every test """ self.modfile = ModFile(0)
class ModFileCommentTests(unittest.TestCase): """ Testing our add_comment_line method """ def setUp(self): """ Initialize some vars we'll need on every test """ self.modfile = ModFile(0) def test_blank(self): self.modfile.add_comment_line('') self.assertEqual(self.modfile.mod_desc, []) def test_single(self): self.modfile.add_comment_line('testing') self.assertEqual(self.modfile.mod_desc, ['testing']) def test_strips(self): for char in ['/', '#', ' ', "\n", "\r", "\t"]: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line('{}testing{}'.format(char, char)) self.assertEqual(self.modfile.mod_desc, ['testing']) def test_all_strips(self): self.modfile.add_comment_line("/#\n\r\t testing/#\n\r\t") self.assertEqual(self.modfile.mod_desc, ['testing']) def test_two(self): self.modfile.add_comment_line('testing') self.modfile.add_comment_line('testing2') self.assertEqual(self.modfile.mod_desc, ['testing', 'testing2']) def test_double_empty(self): self.modfile.add_comment_line('testing') self.modfile.add_comment_line('') self.modfile.add_comment_line('') self.assertEqual(self.modfile.mod_desc, ['testing', '']) def test_initial_ascii_art(self): for char in ['_', '/', '\\', '.', ':', '|', '#', '~', ' ', "\t"]: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line(char) self.assertEqual(self.modfile.mod_desc, []) def test_after_ascii_art_no_whitespace_or_comments(self): for char in ['_', '\\', '.', ':', '|', '~']: with self.subTest(char=char): self.modfile = ModFile(0) self.modfile.add_comment_line('testing') self.modfile.add_comment_line(char) self.assertEqual(self.modfile.mod_desc, ['testing', char]) def test_initial_ascii_art_all(self): self.modfile.add_comment_line("_/\\.:| \t#~") self.assertEqual(self.modfile.mod_desc, []) def test_initial_ascii_art_after(self): art = "_/\\.:|# \t~" self.modfile.add_comment_line('testing') self.modfile.add_comment_line(art) self.assertEqual(self.modfile.mod_desc, ['testing', art]) def test_matched_title(self): title = 'Mod Title' self.assertEqual(self.modfile.mod_title, None) self.modfile.add_comment_line(title, match_title=title) self.assertEqual(self.modfile.mod_title, title) self.assertEqual(self.modfile.mod_desc, []) def test_close_title(self): title = 'Mod Title' self.assertEqual(self.modfile.mod_title, None) self.modfile.add_comment_line(title, match_title='{}z'.format(title)) self.assertEqual(self.modfile.mod_title, title) self.assertEqual(self.modfile.mod_desc, []) def test_unmatched_title(self): title = 'Mod Title' self.assertEqual(self.modfile.mod_title, None) self.modfile.add_comment_line(title, match_title='Totally Different') self.assertEqual(self.modfile.mod_title, None) self.assertEqual(self.modfile.mod_desc, [title]) def test_matched_title_not_first(self): title = 'Mod Title' self.assertEqual(self.modfile.mod_title, None) self.modfile.add_comment_line('testing') self.modfile.add_comment_line(title, match_title=title) self.assertEqual(self.modfile.mod_title, None) self.assertEqual(self.modfile.mod_desc, ['testing', title])
class ModFileFTTests(unittest.TestCase): """ Testing importing a FilterTool-formatted file """ def setUp(self): """ Initialize some vars we'll need on every test. FT format is not especially structured, so not a lot of work to do here. """ self.modfile = ModFile(0) self.df = io.StringIO() def set_df_contents(self, cat_name, lines): """ Sets the contents of the "file" that we're gonna read in. We enforce a bit of FilterTool-style formatting in here, though it's quite a bit more freeform than BLCMM. There'll be empty lines inbetween everything, though """ print('#<{}>'.format(cat_name), file=self.df) print('', file=self.df) for line in lines: print(line, file=self.df) print('', file=self.df) print('#</{}>'.format(cat_name), file=self.df) print('', file=self.df) print('set Transient.SparkServiceConfiguration_6 Keys ("whatever")', file=self.df) self.df.seek(0) def test_load_commentless(self): self.set_df_contents('Mod Name', [ 'set foo bar baz', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_title, 'Mod Name') self.assertEqual(self.modfile.mod_desc, []) def test_one_comment(self): self.set_df_contents('Mod Name', [ 'Testing', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_two_comments(self): self.set_df_contents('Mod Name', [ 'Testing', 'Testing 2', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing', 'Testing 2']) def test_two_comments_interrupted(self): self.set_df_contents('Mod Name', [ 'Testing', 'set foo bar baz', 'Testing 2', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_two_comments_interrupted_cat(self): self.set_df_contents('Mod Name', [ 'Testing', '#<Category>', 'Testing 2', '#</Category>', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_two_comments_interrupted_hotfix(self): self.set_df_contents('Mod Name', [ 'Testing', '#<hotfix><key>test</key><value>moretest</value></hotfix>', 'Testing 2', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_comment_nested_cat(self): self.set_df_contents('Mod Name', [ '#<Category>', 'Testing', '#</Category>', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, []) def test_comment_nested_cat_description(self): self.set_df_contents('Mod Name', [ '#<Description>', 'Testing', '#</Description>', ]) self.modfile.load_ft(self.df) self.assertEqual(self.modfile.mod_desc, ['Testing'])
class ModFileUnknownTests(unittest.TestCase): """ Testing importing an unknown-format file. The main wrinkle here is that the filename is about the only reliable way of determining a mod title, and we're going to attempt to Levenshtein-match that name versus comment lines we read. """ def setUp(self): """ Initialize some vars we'll need on every test. """ self.modfile = ModFile(0) self.modfile.full_filename = 'modname.txt' self.df = io.StringIO() def set_df_contents(self, lines): """ Sets the contents of the "file" that we're gonna read in. """ for line in lines: print(line, file=self.df) self.df.seek(0) def test_load_commentless(self): self.set_df_contents([ 'set foo bar baz', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'modname') self.assertEqual(self.modfile.mod_desc, []) def test_default_title_no_ext(self): self.modfile.full_filename = 'no_extension' self.set_df_contents([]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'no_extension') def test_default_title_multiple_ext(self): self.modfile.full_filename = 'filename.txt.txt' self.set_df_contents([]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'filename.txt') def test_set_title(self): self.set_df_contents([ 'Mod Name', 'set foo bar baz', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'Mod Name') self.assertEqual(self.modfile.mod_desc, []) def test_set_title_and_comment(self): # 'Mod Name' matches the default 'modname' set in setUp() self.set_df_contents([ 'Mod Name', 'Testing', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'Mod Name') self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_load_one_comment(self): self.set_df_contents([ 'Testing', 'set foo bar baz', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'modname') self.assertEqual(self.modfile.mod_desc, ['Testing']) def test_load_two_comments(self): self.set_df_contents([ 'Testing', 'Testing 2', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'modname') self.assertEqual(self.modfile.mod_desc, ['Testing', 'Testing 2']) def test_comment_after_set(self): self.set_df_contents([ 'set foo bar baz', 'Testing', ]) self.modfile.load_unknown(self.df) self.assertEqual(self.modfile.mod_title, 'modname') self.assertEqual(self.modfile.mod_desc, [])