Exemplo n.º 1
0
 def test_config_reader_bad(self):
     try:
         cfg = reusables.config_namespace(
             reusables.join_paths(test_root, "data", "test_bad_config.ini"))
     except AttributeError:
         pass
     else:
         assert False
Exemplo n.º 2
0
 def test_config_reader_bad(self):
     try:
         cfg = reusables.config_namespace(
             reusables.join_paths(test_root, "data", "test_bad_config.ini"))
     except AttributeError:
         pass
     else:
         assert False
Exemplo n.º 3
0
    def test_config_reader(self):
        cfg = reusables.config_namespace(
            reusables.join_paths(test_root, "data", "test_config.ini"))

        assert isinstance(cfg, reusables.ConfigNamespace)
        assert cfg.General.example == "A regular string"

        assert cfg["Section 2"].list(
            "exampleList", mod=lambda x: int(x)) == [234, 123, 234, 543]
Exemplo n.º 4
0
    def test_config_reader(self):
        cfg = reusables.config_namespace(
            reusables.join_paths(test_root, "data", "test_config.ini"))

        assert isinstance(cfg, reusables.ConfigNamespace)
        assert cfg.General.example == "A regular string"

        assert cfg["Section 2"].list(
            "exampleList", mod=lambda x: int(x)) == [234, 123, 234, 543]
Exemplo n.º 5
0
    def test_json_save(self):
        test_data = {"Hello": ["how", "are"], "You": "?", "I'm": True, "fine": 5}
        afile = reusables.join_paths(test_root, "test.json")
        try:
            reusables.save_json(test_data, afile)
            out_data = reusables.load_json(afile)
        finally:
            try:
                os.unlink(afile)
            except OSError:
                pass

        assert out_data == test_data
Exemplo n.º 6
0
    def test_json_save(self):
        test_data = {
            "Hello": ["how", "are"],
            "You": "?",
            "I'm": True,
            "fine": 5
        }
        afile = reusables.join_paths(test_root, "test.json")
        try:
            reusables.save_json(test_data, afile)
            out_data = reusables.load_json(afile)
        finally:
            try:
                os.unlink(afile)
            except OSError:
                pass

        assert out_data == test_data
Exemplo n.º 7
0
    def test_csv(self):
        matrix = [["Date", "System", "Size", "INFO"],
                  ["2016-05-10", "MAIN", 456, [1, 2]],
                  ["2016-06-11", "SECONDARY", 4556, 66]]
        afile = reusables.join_paths(test_root, "test.csv")
        try:
            reusables.list_to_csv(matrix, afile)
            from_save = reusables.csv_to_list(afile)
        finally:
            try:
                os.unlink(afile)
            except OSError:
                pass

        assert len(from_save) == 3
        assert from_save[0] == ["Date", "System", "Size", "INFO"], from_save[0]
        assert from_save[1] == ["2016-05-10", "MAIN", '456', '[1, 2]'], from_save[1]
        assert from_save[2] == ["2016-06-11", "SECONDARY", '4556', '66'], from_save[2]
Exemplo n.º 8
0
    def test_csv(self):
        matrix = [["Date", "System", "Size", "INFO"],
                  ["2016-05-10", "MAIN", 456, [1, 2]],
                  ["2016-06-11", "SECONDARY", 4556, 66]]
        afile = reusables.join_paths(test_root, "test.csv")
        try:
            reusables.list_to_csv(matrix, afile)
            from_save = reusables.csv_to_list(afile)
        finally:
            try:
                os.unlink(afile)
            except OSError:
                pass

        assert len(from_save) == 3
        assert from_save[0] == ["Date", "System", "Size", "INFO"], from_save[0]
        assert from_save[1] == ["2016-05-10", "MAIN", '456',
                                '[1, 2]'], from_save[1]
        assert from_save[2] == ["2016-06-11", "SECONDARY", '4556',
                                '66'], from_save[2]
Exemplo n.º 9
0
 def test_win_join_path_dirty(self):
     resp = reusables.join_paths('C:\\test\\', 'D:\\dirty',
                                 ' path.file ')
     assert resp == 'D:\\dirty\\path.file', resp
Exemplo n.º 10
0
 def test_join_path_clean_strict(self):
     resp = reusables.join_paths('/test/', 'clean/', 'path/')
     assert resp == '/test/clean/path/', resp
Exemplo n.º 11
0
 def test_win_join_path_clean(self):
     resp = reusables.join_paths('C:\\test', 'clean\\',
                                 'path').rstrip("\\")
     assert resp == 'C:\\test\\clean\\path', resp
Exemplo n.º 12
0
 def test_dup_empty(self):
     empty_file = reusables.join_paths(test_root, "empty")
     reusables.touch(empty_file)
     self._extract_structure()
     b = [x for x in reusables.dup_finder(empty_file, test_root)]
     print(b)
Exemplo n.º 13
0
 def test_join_path_dirty(self):
     resp = reusables.join_paths('/test/', '/dirty/', ' path.file ')
     assert resp == '/test/dirty/path.file', resp
Exemplo n.º 14
0
 def test_join_path_dirty(self):
     resp = reusables.join_paths('/test/', '/dirty/', ' path.file ')
     assert resp == '/test/dirty/path.file', resp
Exemplo n.º 15
0
 def test_dup_empty(self):
     empty_file = reusables.join_paths(test_root, "empty")
     touch(empty_file)
     self._extract_structure()
     b = [x for x in reusables.dup_finder_generator(empty_file, test_root)]
     print(b)
Exemplo n.º 16
0
 def test_join_path_clean_strict(self):
     resp = reusables.join_paths('/test/', 'clean/', 'path/')
     assert resp == '/test/clean/path/', resp
Exemplo n.º 17
0
 def test_win_join_path_clean(self):
     resp = reusables.join_paths('C:\\test', 'clean\\', 'path').rstrip("\\")
     assert resp == 'C:\\test\\clean\\path', resp
Exemplo n.º 18
0
 def test_win_join_path_dirty(self):
     resp = reusables.join_paths('C:\\test\\', 'D:\\dirty', ' path.file ')
     assert resp == 'D:\\dirty\\path.file', resp