<commit_before>import synapse.exc as s_exc

import synapse.tests.common as s_test

class FileTest(s_test.SynTest):

    def test_model_filebytes(self):

        # test that sha256: form kicks out a sha256 sub.
        with self.getTestCore() as core:
            valu = 'sha256:' + ('a' * 64)
            norm, info = core.model.type('file:bytes').norm(valu)
            self.eq(info['subs']['sha256'], 'a' * 64)

            norm, info = core.model.type('file:bytes').norm('b' * 64)
            self.eq(info['subs']['sha256'], 'b' * 64)

    def test_model_file_types(self):

        with self.getTestCore() as core:

            base = core.model.type('file:base')
            path = core.model.type('file:path')

            norm, info = base.norm('FOO.EXE')
            subs = info.get('subs')

            self.eq('foo.exe', norm)
            self.eq('exe', subs.get('ext'))

            self.raises(s_exc.BadTypeValu, base.norm, 'foo/bar.exe')
            self.raises(s_exc.BadTypeValu, base.norm, '/haha')

            norm, info = path.norm('c:\\Windows\\System32\\calc.exe')

            self.eq(norm, 'c:/windows/system32/calc.exe')
            self.eq(info['subs']['dir'], 'c:/windows/system32')
            self.eq(info['subs']['base'], 'calc.exe')<commit_msg>Add sad path testing for file:bytes.<commit_after>import synapse.exc as s_exc
import synapse.common as s_common

import synapse.tests.common as s_test

class FileTest(s_test.SynTest):

    def test_model_filebytes(self):

        # test that sha256: form kicks out a sha256 sub.
        with self.getTestCore() as core:
            valu = 'sha256:' + ('a' * 64)
            fbyts = core.model.type('file:bytes')
            norm, info = fbyts.norm(valu)
            self.eq(info['subs']['sha256'], 'a' * 64)

            norm, info = fbyts.norm('b' * 64)
            self.eq(info['subs']['sha256'], 'b' * 64)

            self.raises(s_exc.BadTypeValu, fbyts.norm, s_common.guid())
            self.raises(s_exc.BadTypeValu, fbyts.norm, 'guid:0101')
            self.raises(s_exc.BadTypeValu, fbyts.norm, 'helo:moto')
            self.raises(s_exc.BadTypeValu, fbyts.norm, f'sha256:{s_common.guid()}')

    def test_model_file_types(self):

        with self.getTestCore() as core:

            base = core.model.type('file:base')
            path = core.model.type('file:path')

            norm, info = base.norm('FOO.EXE')
            subs = info.get('subs')

            self.eq('foo.exe', norm)
            self.eq('exe', subs.get('ext'))

            self.raises(s_exc.BadTypeValu, base.norm, 'foo/bar.exe')
            self.raises(s_exc.BadTypeValu, base.norm, '/haha')

            norm, info = path.norm('c:\\Windows\\System32\\calc.exe')

            self.eq(norm, 'c:/windows/system32/calc.exe')
            self.eq(info['subs']['dir'], 'c:/windows/system32')
            self.eq(info['subs']['base'], 'calc.exe')
{'fraction_non_alphanumeric': 0.1671270718232044, 'fraction_numerical': 0.02244475138121547, 'mean_word_length': 2.2845804988662133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4803365', 'n_tokens_mistral': 1072, 'n_tokens_neox': 984, 'n_words': 174}